Saturday, March 24, 2012

System.Net.WebClient and UploadFile() Problem

I am using WebClient to upload a file to a remote server. The call I'm
making looks as follows:

webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/Federation.Zip",
@dotnet.itags.org."C:\Temp\Federation.Zip");

'Federation' is a virtual directory on the server I'm attempting to upload
the file to. The URL is valid and the file I'm attempting to transfer
exists. I keep getting 404 errors (not found). It's not clear to me exactly
what cannot be found. If I attempt to download this exact file from the same
exact URL using webClient.DownloadFile, it works fine!

Thanks for the help - Amos.You can not simply upload file on a server.
Something should wait for that file at the server end.

So url http://sdtpcal.someserver.com/Feder.../Federation.Zip to
download file looks correct.

but to upload you must write an ASPX page that will accept file and save to
the folder on a server.

George.

"Amos Soma" <amos_j_soma@.yahoo.comwrote in message
news:OqGt9oK7GHA.1248@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I am using WebClient to upload a file to a remote server. The call I'm
>making looks as follows:
>
webClient.UploadFile("http://sdtpcal.someserver.com/Federation/Databases/Federation.Zip",
@."C:\Temp\Federation.Zip");
>
'Federation' is a virtual directory on the server I'm attempting to upload
the file to. The URL is valid and the file I'm attempting to transfer
exists. I keep getting 404 errors (not found). It's not clear to me
exactly what cannot be found. If I attempt to download this exact file
from the same exact URL using webClient.DownloadFile, it works fine!
>
Thanks for the help - Amos.
>
>


Thus wrote George Ter-Saakov,

Quote:

Originally Posted by

You can not simply upload file on a server.
Something should wait for that file at the server end.
So url
http://sdtpcal.someserver.com/Feder.../Federation.Zip to
download file looks correct.
>
but to upload you must write an ASPX page that will accept file and
save to the folder on a server.


You only need a web application endpoint for POST requests. If the OP can
use PUT, the web server may support this without any special user code (IIS
does for sure).

Both WebClient.UploadFile(uri, "PUT", fileName) and WebClient.OpenWrite(uri,
"PUT") will do the trick.

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

0 comments:

Post a Comment