Re: HttpWebRequest file upload problem

From: R Reyes (RReyes_at_discussions.microsoft.com)
Date: 09/16/04


Date: Wed, 15 Sep 2004 18:43:03 -0700

Two different web servers I have tried, here they are

Here is the first on a remote web server. I think this is probably a
permissions error and am trying to figure out exactly which ones because
read/write are granted...
File upload failed: System.Net.WebException: The remote server returned an
error: (405) Method Not Allowed.
   at System.Net.HttpWebRequest.CheckFinalStatus()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.HttpWebRequest.GetResponse()
   at myProject.ForumSubmit.uploadFile(String strAttachFile) in
C:\Inetpub\wwwroot\myProject\ForumSubmit.aspx.cs:line 181

Here is the second connection which is just to another folder on my
computer...I also have folder with read/write access so I am not sure why
access is denied.
File upload failed: System.UnauthorizedAccessException: Access to the path
"C:\public\tempFiles\work\docs\myDoc_.doc" is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
   at System.IO.File.OpenRead(String path)
   at myProject.ForumSubmit.uploadFile(String strAttachFile) in
c:\inetpub\wwwroot\myProject\forumsubmit.aspx.cs:line 170

I'm not sure why it's not working or why a folder needs certain access.
Whenever I try uploading files from my computer to any forum online they
don't need to see my folders as having shared access. I just choose the file
click Submit and it works fine for them. So why not here?

BTW, I am working with VS.NET, IIS5, and on a winxp system. I am trying to
connect to a remote web server a friend set up in the first example and from
myself to myself in the second. This upload file code will be used for a
website forum I am creating so that users can attach pictures or files with
their submissions. Let me know if you need any more info and thanks for your
help.

"Branimir Giurov" wrote:

> Hi there -
>
> what is the exception that's being thrown? What are the permissions that the
> app runs with?
> If you're starting it from a web site, you might have problems with the Code
> Access Security policies on the machine ...
>
> Can you please be more specific about the enviornment you/your users are
> gonna use?
>
> Cheers,
> Branimir
>
> --
> Branimir Giurov
> MCSD.NET, MCDBA
> www.sofiadev.org
>
>
>
> "R Reyes" <RReyes@discussions.microsoft.com> wrote in message
> news:515B955F-1E74-40D3-84A8-1A24EA30ABEA@microsoft.com...
> >I am trying to code a file uploader (for forum/email attachments) from the
> > client computer to a remote web server via the PUT method (since POST is
> > not
> > allowed [405 error]). However, the upload works ONLY when the file is
> > inside
> > a shared folder on my computer. If I try to upload from any other folder
> > it
> > does not work. Why is this?
> >
> > Reason being that whenever I upload files on other forums or websites I
> > know
> > I don't need to have my folder shared on my network. I just enter a path
> > and
> > do it. Am I missing a setting on the remote server? Am I coding
> > something
> > wrong? Please help. Here is my code:
> >
> > // Upload the file to a web server using the HttpWebRequest object
> > string strAttachFile = "C:\temp\blah.txt";
> > HttpWebRequest myHttpWebRequest =
> > (HttpWebRequest)WebRequest.Create("http://localhost/myFile.txt"); // The
> > server path and name of the file we are saving
> > BinaryReader rdr = new BinaryReader(File.OpenRead(@strAttachFile)); //
> > The
> > client path and name of the file we are uploading
> > byte[] data = rdr.ReadBytes((int)rdr.BaseStream.Length);
> > myHttpWebRequest.Method = "PUT";
> > myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
> > myHttpWebRequest.SendChunked = true;
> > myHttpWebRequest.Timeout = 10000;
> > myHttpWebRequest.ContentLength = data.Length;
> > myHttpWebRequest.KeepAlive = true;
> > Stream s = myHttpWebRequest.GetRequestStream();
> > s.Write(data, 0, data.Length);
> > s.Close();
> > HttpWebResponse myHttpWebResponse =
> > (HttpWebResponse)myHttpWebRequest.GetResponse();
> > myHttpWebResponse.Close();
>
>
>



Relevant Pages

  • Re: The info you requested
    ... > The folder permissions in my computer are set for read/write access. ... > upload a file from their computer to wherever the web server is. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: my gif files dont work on the internet
    ... web server mob and you might be right go to another web server thanks again ... images and delete old files as I suggested. ... folder on your hard drive, ... but i have deleted the site and am trying to upload it again with the ...
    (microsoft.public.publisher.webdesign)
  • Re: HttpWebRequest file upload problem
    ... > client computer to a remote web server via the PUT method (since POST is ... the upload works ONLY when the file is ... If I try to upload from any other folder ...
    (microsoft.public.dotnet.languages.csharp)
  • HttpWebRequest file upload problem
    ... client computer to a remote web server via the PUT method (since POST is not ... the upload works ONLY when the file is inside ...
    (microsoft.public.dotnet.languages.csharp)
  • File uploading and downloading - help
    ... Is there a way for a client to upload a file to a folder that is not apart ... of the web server? ...
    (microsoft.public.dotnet.framework.aspnet)