Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem : Webclient.UploadFile method gives me exception "remote server return an error 404 not found"

Scenario : I have a virtual directory on my server(http://xx.xx.xx.xx/Uploadfile)
now i want to upload a file from my local machine to server. i used following code

C#
wcUpload = new WebClient();
wcUpload.Credentials = CredentialCache.DefaultCredentials;
wcUpload.UploadFile("http://xx.xx.xx.xx/Uploadfile/test.pdf, @"C:\test.pdf"); //this line throws exception


i have test.pdf exist on my C:\

i have checked for access permission to virtual directory, it is fine.

what should be the possible solution.
any help ?
Posted

Shreya,
It tries to look for the file http://xx.xx.xx.xx/Uploadfile/test.pdf which doesn't exist. You need to create a page there which accepts the file and store at directory.
VB
wcUpload.UploadFile("http://xx.xx.xx.xx/upload.aspx, @"C:\test.pdf")

See this MSDN example http://msdn.microsoft.com/en-us/library/36s52zhs.aspx[^]
 
Share this answer
 
v2
Comments
koolprasad2003 24-Aug-11 3:13am    
Good Answer Prerak, +5
shreya1987 24-Aug-11 3:20am    
thanks prerak solved.
webClient.DownloadFile() will allow direct download from source to destination, but this is not the case with UploadFile() method.
There should exist some reciever page to get the file and that page will then POST your file to destnation.

As prerak quoted Create upload.aspx page at server put following code in it and call it from your client to upload file

C#
foreach(string f in Request.Files.AllKeys) {
		HttpPostedFile file = Request.Files[f];
		file.SaveAs("Path to save file\\" + file.FileName);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900