WebClient.UploadFile adds stuff to the file.

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.
 
T

Tim_Mac

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
 
J

Joerg Jooss

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,
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top