WebClient.UploadFile adds stuff to the file.

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

I'm trying to upload stuff using the UploadFile from WebClient and I've
noticed that it adds header and footers to the stream.

Is there any way to get rid of that automatically?

I'm using
webclient.UploadFile("http://127.0.0.1/ECSWebServices/UploadItem.aspx",
"POST", "C:\Test.txt")

and the file ends up looking like:

-----------------------8c8a61883d4721e
Content-Disposition: form-data; name="file"; filename="test2.txt"
Content-Type: application/octet-stream

This is a test file.
-----------------------8c8a61883d4721e


How do I get rid of the header/footer?

TIA - Jeff.
 
you can be sure that there is something going on in your UploadItem.aspx
page that is writing the header and footer.
the UploadFile method works as you would expect it to.

the sample code from the SDK is as follows:

void Page_Load(object sender, EventArgs e)
{
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs("c:\\inetpub\\test\\UploadedFiles\\" + file.FileName);
}}


what code are you using?
tim
 
Thus wrote UJ,
I'm trying to upload stuff using the UploadFile from WebClient and
I've noticed that it adds header and footers to the stream.

Is there any way to get rid of that automatically?

I'm using
webclient.UploadFile("http://127.0.0.1/ECSWebServices/UploadItem.aspx"
, "POST", "C:\Test.txt")

and the file ends up looking like:

-----------------------8c8a61883d4721e
Content-Disposition: form-data; name="file"; filename="test2.txt"
Content-Type: application/octet-stream
This is a test file.
-----------------------8c8a61883d4721e
How do I get rid of the header/footer?

TIA - Jeff.

That's a multipart/form-data request and supposed to look like that.

Either use WebClient.UploadData() or make sure the server side knows how
to deal with a multipart/form-data request.

Cheers,
 
Back
Top