473,412 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

WebClient.UploadFile adds stuff to the file.

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.
Sep 14 '06 #1
2 3943
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
"UJ" <fr**@nowhere.comwrote in message
news:OT**************@TK2MSFTNGP03.phx.gbl...
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.


Sep 15 '06 #2
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,
--
Joerg Jooss
ne********@joergjooss.de
Sep 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David W | last post by:
I am trying to upload a file from a user's system to my web server. I found code using the WebClient.UploadFile method. However, the uploaded file is from the server's hard drive not the user's...
0
by: Saverio Tedeschi | last post by:
Hi all gurus, forgive me if I submit a 2nd post, but I'm no more able to see my question. So: I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-))...
2
by: marfi95 | last post by:
Hello all. I'm not sure if this is the correct place to post this, but if not please let me know. This is my situation. I have a simple problem, but am having problems doing this. I'm...
1
by: Phillip N Rounds | last post by:
I'm having problems using the WebClient.UploadFile() command. I have MySender.ASPX which is supposed to upload two files to the server. There is also ConsumeFileUpload.aspx which is intended to...
2
by: Daniel | last post by:
As you may have guessed I'm trying to upload a file to a php server using the WebClient.UploadFile function, however the function never returns. Instead it chews up memory (fairly slowly) until it...
3
by: =?Utf-8?B?dmFzaW1v?= | last post by:
Have the following code: wkLocalPath = "C:\A\1.jpg" wkServerPath = "http://servername/dirname/1.jpg" wcClient.Credentials = New NetworkCredential("UID", "PW") wcClient.UploadFile(wkServerPath,...
5
by: Svinja | last post by:
Hi, i am using WebClient.UploadFile to upload a file on my web page, code: WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential(userName, pass);...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
5
by: benmess | last post by:
This code snippet works fine on a localhost because the file you upload resides on the host machine (where FileServer.aspx is a new page invoked from the UploadFile call) function...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.