G
Guest
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();
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();