Upload file via HTTP

  • Thread starter Thread starter Paw Pedersen
  • Start date Start date
P

Paw Pedersen

I would like to do the same in C# code as a simple html page does with this
code:
<form action="http://vej-w2k3-psp/sslmodtag/WebForm1.aspx" method="post"
ENCTYPE="multipart/form-data"
ID="Form1">
<input type="file" name="test" ID="File1"> <input type="submit"
ID="Submit1" NAME="Submit1" />
</form>

Upload a file to a http page.

I know I can do it with the following C# code:

WebClient myWebClient = new WebClient();
byte[] responseArray =
myWebClient.UploadFile("http://vej-w2k3-psp/sslmodtag/WebForm1.aspx","POST",
@"c:\fileName");

But this will put the file in the request.Files["file"] (the "file" index),
and I wanna be able to decide the index myself. As you are able to with the
html code and the "name" attribut.
Anybody know's how to do that?

Regards Paw
 
System.Collections.Specialized.NameValueCollection requestParameters=new
System.Collections.Specialized.NameValueCollection();

requestParameters.Add("file",....);

using(System.Net.WebClient webClient=new System.Net.WebClient())

{byte[] replyBytes=webClient.UploadValues(uri,"POST",requestParameters);}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top