WebClient Upload

G

Guest

Have the following code:
wkLocalPath = "C:\A\1.jpg"
wkServerPath = "http://servername/dirname/1.jpg"
wcClient.Credentials = New NetworkCredential("UID", "PW")
wcClient.UploadFile(wkServerPath, "PUT", wkLocalPath)

File exists on C.
Dir exist on server (ASPNET user and Admin user have full rights) (tried both)
Created virtual for Dirname and gave it write access in properties)
"POST" gives same results.

with or without credentials, throws: (404) Not Found
It looks like a security permissions thing. Just can't figure out what.
Someone thought it was a bug in Webclient since 1.0

Webclient download works fine.
Don't have a web page to put a file or Upload control on. Need to pull data
from client machine on the fly through inline code. Trying to create a DLL as
a service mod to do upload/Download from server.

Any help would be appreciated.
 
B

bruce barker

the serverpath needs to be a url that supports a fileupload post, not
where to write the file. the error is because an image does not suppport
a post.

if you want to access a webserver as a filesystem, look at webdav.

-- bruce (sqlwork.com)
 
G

Guest

Thanks for your reply.
I'm a little confused (as always).
What do you mean by "the serverpath needs to be a url that supports a
fileupload post, not where to write the file"? Everything I read indicates
that the file name to create is appended to the back of the URL. I created a
virtual dir for the physical path and gave it write access.
I tried a POST as a last resort. I was under the impression that the POST is
for text data only. I am using a PUT which I thought handled all data streams.
I thought the 404(not found) was actually a security error not an
operational problem. Do you think I wrong in that assumption?
Thanks Vic
 
G

George Ter-Saakov

The method PUT must be supported on a server. So server in response to
method PUT need to get the file and save it to proper folder.

By default (if you did nit do anything special) IIS does not support method
PUT. At least I believe so.

but you will have much better chances of getting it to work if you create
your onw uploadfile.aspx that accempt uploaded file

sample from MSDN:

MyUpload.aspx
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>

<Script language="C#" runat=server>
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);
}
}

Code to upload file
myWebClient.UploadFile("http://myserver/MyUpload.aspx", "POST",
"filename.jpg");


George.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top