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
Re: Using webbrowser to fill in File box
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();
});
}