WebClient.UploadFile results in corrupted file

wile_e_coyote used Ask the Experts™
I'm trying to use WebClient.UploadFile to copy a file from a client to a web server.  The file contains "binary" data for a 3rd party program.  The 3rd party program is unable to read the web server's copy of the file.  A quick comparison reveals that the original file size is 1,687 bytes but the copied file size is 1,879 bytes.  Is there some attribute/property I can set so that an exact copy is made?

Here is my code:
public void upload (string pTargetURI, string pSourceFname)
 WebClient lClient = new WebClient();
 lClient.Credentials =
 lClient.UploadFile (pTargetURI, "PUT", pSourceFname);
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Try another method? Like POST.

Also, the filesystems on your local machine and the server's are different? If they are different this can show difference in the file size itself.


I get an error 405 (method not allowed) when I use POST.  Both machines are same OS and file system.  If I copy the file from one to the other via windows explorer, it works fine.  But if I copy via WebClient,  then the 3rd party utility can't read the file.


I solved the problem by opening the file as a binary stream and using the WebClient.OpenWrite and WebClient.Write methods.  Evidently, WebClient.Upload file will not make an exact copy.
as per request moved to paq points refunded


Jgould-EE Moderator

Sir coyote

can you explain a little more? code?

// Daniel

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial