Re: HttpWebRequest file upload problem
From: R Reyes (RReyes_at_discussions.microsoft.com)
Date: 09/16/04
- Next message: Mattias Sjögren: "Re: Dll and namespace scenarios! Help!"
- Previous message: Mattias Sjögren: "Re: delegates that add functionality to the delegated method"
- In reply to: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Next in thread: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Reply: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 16 Sep 2004 12:03:02 -0700
both actually, but the one that works is PUT. i don't think there is a
problem with the code since it works some times. it only breaks when i am
switching folders from the shared folders on my computer to the unshared
ones. but like i said, having them shared shouldn't matter because if i'm
able to upload to different websites then it shouldn't have to be different
with my project.
Here is my code:
strAttachFile = "C:\temp\blah.txt";
string strFileName = strAttachFile;
strFileName = Path.GetFileName(strFileName);
// Upload the file to a web server using the HttpWebRequest object
// When we create the object we will provide the server path
// and name of the file we are saving
// HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create("http://www.somelocation.com:8080/"+strFileName);
// The client path and name of the file we are uploading
BinaryReader rdr = new BinaryReader(File.OpenRead(@strAttachFile));
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();
"Joerg Jooss" wrote:
> R Reyes wrote:
> > 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
>
> What did you try? A PUT? A POST?
>
> > 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
>
> Does the ASP.NET process have write permission for
> C:\public\tempFiles\work\docs?
>
> > I'm not sure why it's not working or why a folder needs certain
> > access.
>
> Because of security? It's not a good idea to allow exposed services like a
> web server or an application server to do everything on your production
> server.
>
> > 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?
>
> What has this to do with shared folders on your system? All you need is to
> understand the security implications and configure your system accordingly.
>
> Cheers,
>
> --
> Joerg Jooss
> joerg.jooss@gmx.net
>
>
>
- Next message: Mattias Sjögren: "Re: Dll and namespace scenarios! Help!"
- Previous message: Mattias Sjögren: "Re: delegates that add functionality to the delegated method"
- In reply to: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Next in thread: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Reply: Joerg Jooss: "Re: HttpWebRequest file upload problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|