UploadFile

  • Thread starter Thread starter Ching-Lung
  • Start date Start date
C

Ching-Lung

Hi,

UploadFile() is always throwing WebException: "The remote
server returned an error: (405) Method Not Allowed."

Is there any setting that I miss? IIS setting?

Please help, thanks!
-CL
 
Does your form tag look something like this?

<FORM id="Form1" method="post" encType="multipart/form-data" runat="server">
 
you need to add this:

encType="multipart/form-data"

to the form tag.



Thanks,

Manit Chanthavong
 
Hi,

I've tried adding encType="multipart/form-data" it doesn't
throw the 405 web exception but my <input type=file>
doesn't work. For some reason, <input type=file> is
an "undefined" object.

Any idea?
-CL
 
Ching-Lung said:
Hi,

UploadFile() is always throwing WebException: "The remote
server returned an error: (405) Method Not Allowed."

I guess that is WebClient.UploadFile(). Well, if you don't specify the
HTTP verb, it will post the file. In that case, there must be some web
application handling the file upload -- which seems not to be case here.

For a "pure" (no web app) HTTP file upload, try HTTP PUT:

string url = "http://host/vdir/test.txt";
WebClient client = new WebClient();
byte[] response = client.UploadFile(url, "PUT", @"C:\temp\test.txt");

This requires write permissions on the virtual directory "vdir".

Cheers,
 
Back
Top