1

I am trying to upload a file automatically using my webBrowser. Let me explain : I have a form with an "input type='file' " element and i am trying to automatically add a file into it.

I already tried this and this and it still doesn't work.

Here is my code :

private void createSystem(string fileUpload)
{
    webBrowser1.Navigate("https://test.com/OrderMngt/uploadclient.aspx");
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Document.GetElementById("UploadFile").Focus();
    SendKeys.Send(" C:\\Users\\me\\Downloads\\Upload\\file.csv{ENTER}");
            return;
}

The web page is reached, the "Choose File Dialog" is opened but the value oh the path is always empty (except if I fill it manually of course -_- ).

Do you have any idea? Thanks!

Community
  • 1
  • 1
Creed
  • 163
  • 1
  • 1
  • 13

1 Answers1

0

It's not possible due to security restrictions in the browser.

Brian
  • 37,399
  • 24
  • 94
  • 109
  • Can we work around the problem or do it another way? – Creed Jul 09 '14 at 06:56
  • It might be possible with Flash, though I would be a bit surprised if it did since that would have the same security issues as doing it in HTML (I'm not a Flash developer so I'm not sure). Of course, Flash only works on PCs and it's questionable for how long it will continue to be supported. Other than that, you would have to install something on the users machine and do it outside of the browser (such as a Click-Once deployed WinForms application). – Brian Jul 09 '14 at 15:48