UploadFile

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
 
M

Manit Chanthavong

Does your form tag look something like this?

<FORM id="Form1" method="post" encType="multipart/form-data" runat="server">
 
M

Manit Chanthavong

you need to add this:

encType="multipart/form-data"

to the form tag.



Thanks,

Manit Chanthavong
 
C

Ching-Lung

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
 
J

Joerg Jooss

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,
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top