I am trying to make a Windows Forms Program to automatically upload a file to website.
The website has a "Browse..." button from the input type="file">
tag, on which I InvokeMember("click")
that triggers the file picker, but I am unable to interact with it.
I am not familiar with that control. I have tried with SendKeys.Send("quotes.html") : SendKeys.Send(Chr(13))
, with no success at all. The SendKeys.Send
commands are executed only after I manually close the file picker.
Does anyone have an idea how to choose a file in this <input type="file">
control using VB.NET?
Edit #1 /08.04.2015 13:00/:
The web service, where I upload the files is a 3rd party application, which I cannot modify. I just want to interact with it so that my application can automatically upload the file, by interacting with the pop-up, file upload form, which appears, but I do not know how to do that.
The part of my code for this procedure is:
For Each OneElement In WebBrowser1.Document.GetElementsByTagName("input")
If OneElement.GetAttribute("type") = "file" Then
If OneElement.GetAttribute("name") = "file[]" Then
'Clicking the "Browse" button of the input type="file"
OneElement.InvokeMember("click")
'MsgBox("Here#13")
'Trying to fill in the "FileName:" textbox of the popup form
SendKeys.Send( _
"strig with the file address - e.g.: C:\Folder\File.html")
'Trying to click the open button, which is in focus
SendKeys.Send(Chr(13))
End If
Exit For
End If
Next
As mentiontioned above, the
SendKeys.Send
is executed only after the file upload pop-up is closed.Edit #2: SOLVED! /14.04.2015 21:00/:
The solution is to make a new thread like that:
...
Dim tr As New System.Threading.Thread(AddressOf SendK)
tr.Start()
OneElement.InvokeMember("click")
tr.Abort()
...
Private Sub SendK()
Threading.Thread.Sleep(2000) ' could be less
SendKeys.SendWait("C:\TheFilePath.html") 'the file address path
SendKeys.SendWait(Chr(13))
End Sub
For whoever whants to upgrade it, as it a raw solution:
1. May be the new thread can be associated with the onclick event of the button;