Drake
Drake

Reputation: 3891

C# upload file to website

I am attempting to post a reply to an image board website. It can be done through a winform web browser control or http request. The issue is that with a post, you can upload an image with a input type file element on the page

<input type="file" />

For security reasons, I cannot set the value of the element to the file I want to upload.

When I use tamper data to see what is passed to the posting page, this is parameter that is passed under POST_DATA

-----------------------------256672629917035
Content-Disposition: form-data; name="upfile"; filename="image_file_name.jpg"
Content-Type: image/jpeg

So how is it possible to simulate a file upload of a input element in C#?

Look closely at the data that was posted, no directory is specified.

Upvotes: 0

Views: 6721

Answers (2)

Alleo
Alleo

Reputation: 8518

If I understood your problem right, you can't determine the directory of the file which was uploaded from your web browser control.

So ... it is impossible. The information about directory isn't given by browser - so it shouldn't be given by web browser control.

As MizardX suggested, it's better to send request using C#.

Upvotes: 0

m.edmondson
m.edmondson

Reputation: 30872

You can simulate any HTTP request through the HttpWebRequest object. Click here for an example.

When you're using the input type file element the browser is creating the request this for you. If you simply recreate this in HttpWebRequest you have full control over all aspects of the request and can modifiy as you wish.

It's probably in your interest to grab a copy of Fiddler.

Upvotes: 2

Related Questions