0

This page acts as a good example for my problem :

http://valums.com/files/2009/ajax-upload/demo-jquery.htm

If you click on the browse button and select a file, the file will be uploaded ajax-style (without posting the whole webpage).

I am developing a C# WinForm application where a WebBrowser control allows me to parse and fill forms automatically and I need to upload a file without opening the "File Browse" window which steals focus away from other windows.

How can this be achieved ?

Eddy
  • 5,320
  • 24
  • 40
Jelly Ama
  • 6,701
  • 3
  • 20
  • 23
  • 1
    No that would be a major security issue if you could codewise force to upload a file from a local disk without the user selecting it. – Eddy Aug 21 '11 at 22:41
  • How do you know which file to upload without browsing through the files? – ShankarSangoli Aug 21 '11 at 22:42
  • @Eddy But I am the user! My WebBrowser control is a web client. It's simply supposed to automate the tedious task of clicking on each file as its job is to upload images regularly to a given website. – Jelly Ama Aug 21 '11 at 22:45
  • @Shankar I am not developing a webpage. This is a winforms automated browser that is supposed to upload images to a website. – Jelly Ama Aug 21 '11 at 22:47
  • I'm not questioning you intentions but if what you ask can be done then it can be abused very easily. If you want to get this done you need something that runs with elevated rights and you can't do this using normal javascript and a standard webbrowser. – Eddy Aug 21 '11 at 22:51
  • @Jelly Ama ahh that is a major difference which I didn't get from your question (and tags). I added a winforms tag for you. Since you run from a client app you can get access to the local filesystem. Been a long time since I played with that browsercontrol and getting interaction between the c# code and js so I don't have a good answer ready for you right now – Eddy Aug 21 '11 at 22:56
  • One last try for me then. If your requirement is just to do the actual upload why go through the webbrowser control and why not create a HttpWebRequest and do the upload directly from c# code? See for instance http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data – Eddy Aug 21 '11 at 22:59
  • How would this work on a webpage like the one I mentioned in the OP ? – Jelly Ama Aug 21 '11 at 23:01
  • @Eddy let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2721/discussion-between-jelly-ama-and-eddy) – Jelly Ama Aug 21 '11 at 23:01

1 Answers1

1

Since you have one specific page you want to automatically populate it's going to be a lot easier to recreate the POST message that is generated using either the WebClient or a HttpWebRequest.

A good code example can be found here and a good tool (one of many though) to see the data that gets posted is fiddler2

Community
  • 1
  • 1
Eddy
  • 5,320
  • 24
  • 40