Monday, March 12, 2012

WebClient Class / Upload File / IIS 405 Error

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...adfiletopic.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 HarmeyerWhat URL are you posting to? The url has to be a dynamic url. For
example,
You can't post to something like:
http://website.com/uploads/
The url has to be something like:
http://website.com/uploads/doupload.aspx
If you are aware of the above, then how large is the file. Your
machine.config file has a max on the length of uploaded files.
sayed
"Grant Harmeyer" <net@.internetapollo.com> wrote in message news:<#MFIUHOlEHA.2140@.TK2MSFTNG
P15.phx.gbl>...
> 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 o
n
> the server. I set the code up nearly exactly as it is shown in the followi
ng
> link:
> http://msdn.microsoft.com/library/d...adfiletopic.asp
> The only thing I did differently is that I also set the BaseAddress proper
ty
> 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
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
"Sayed Hashimi" <hashimi_sayed@.hotmail.com> wrote in message
news:3af23459.0409071305.66c1a2af@.posting.google.com...
> What URL are you posting to? The url has to be a dynamic url. For
> example,
> You can't post to something like:
> http://website.com/uploads/
> The url has to be something like:
> http://website.com/uploads/doupload.aspx
> If you are aware of the above, then how large is the file. Your
> machine.config file has a max on the length of uploaded files.
> sayed
>
> "Grant Harmeyer" <net@.internetapollo.com> wrote in message
> news:<#MFIUHOlEHA.2140@.TK2MSFTNGP15.phx.gbl>...
Grant Harmeyer wrote:
> 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,
Joerg Jooss
joerg.jooss@.gmx.net
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
"Grant Harmeyer" <net@.internetapollo.com> wrote in message news:<uGXU$USlEHA.3356@.TK2MSFTNG
P15.phx.gbl>...
> 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
> "Sayed Hashimi" <hashimi_sayed@.hotmail.com> wrote in message
> news:3af23459.0409071305.66c1a2af@.posting.google.com...

0 comments:

Post a Comment