WebClient Class / Upload File / IIS 405 Error

G

Grant Harmeyer

When I try to upload a file to a resource on my local webserver, my code
catches an exception that a 405 error (method not supported) has occured on
the server. I set the code up nearly exactly as it is shown in the following
link:

http://msdn.microsoft.com/library/d...lrfsystemnetwebclientclassuploadfiletopic.asp

The only thing I did differently is that I also set the BaseAddress property
of the WebClient instance. I have tried using both of the overloaded
UploadFile() methods with the same results each time. Is there any really
good documentation out there on the use of the System.Net.WebClient class?

TIA,

Grant Harmeyer
 
G

Grant Harmeyer

I was unaware that it needed to be a dynamic URL. That clears it up a bit.
Now, how would I take the array of bytes that is read in and then
re-construct the file on the server?

Thanks again,

Grant Harmeyer
 
J

Joerg Jooss

Grant said:
I was unaware that it needed to be a dynamic URL. That clears it up a
bit. Now, how would I take the array of bytes that is read in and then
re-construct the file on the server?

You *don't* need a web application (dynamic URL???) to process a file
upload, if the client uses HTTP PUT instead of HTTP POST. PUT writes the
file directly to the location designated by the URL, but of course you need
to have the appropriate permissions to do that.

When using ASP.NET, you can process an uploaded (POSTed) file using the
HttpRequest.Files property.

Cheers,
 
S

Sayed Hashimi

Grant,

When you use the UploadFile method on the WebClient class, you can
then get to the uploaded file(s) by:

<%@ 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);
}
}

</Script>
<html>
<body>
<p> Upload complete. </p>
</body>
</html>


The Request has a Files collection that you use to get the uploaded
files. This is shown in the link you posted with the original message.
If this isn't what you were asking, please post some of your code so I
can help you further.


sayed
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top