Results 1 to 3 of 3

Thread: Setting a file to upload inside the WebBrowser component

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    20

    Setting a file to upload inside the WebBrowser component

    im using a loop to enter text into text boxes using the following:

    Code:
    Private Sub FillTextbox(ByVal sElement As String, ByVal sString As String)
            Dim z As Integer = 0
    
            While Not SiteIsLoaded
                Application.DoEvents()
            End While
    
                For Each Form As HtmlElement In webby.Document.Forms
                    Dim el2 As HtmlElementCollection = webby.Document.Forms(z).GetElementsByTagName("input")
                    For Each curElement As HtmlElement In el2
                        Dim ControlName As String = curElement.GetAttribute("name").ToString
                        If ControlName = sElement Then  'Add
                            curElement.InnerText = sString
                        End If
                    Next
                    z = z + 1
                Next
    
        End Sub
    But i have a file property, the website has the following code

    <input type="file" size="30" name="torrent" id="torrent"/>

    How can i use a loop similar to above to insert the filename
    Last edited by stewmath; May 13th, 2011 at 10:27 AM. Reason: Better Title

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    20

    Re: Using webbrowser to fill in File box

    anybody?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    20

    Re: Setting a file to upload inside the WebBrowser component

    Ive found a way of doing this in ASP.net, can someone please convert?

    Code:
    private void webBrowser1_DocumentCompleted(object sender, 
                 WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlElement form = webBrowser1.Document.Forms[0];
        form.AttachEventHandler("onsubmit", delegate(object o, EventArgs arg)
            {
                FormToMultipartPostData postData = 
                    new FormToMultipartPostData(webBrowser1, form);
                postData.SetFile("fileField", @"C:\windows\win.ini");
                postData.Submit();
            });
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width