I have run into an issue where the following code works on a Windows 2003 machine and now that we are upgrading to 2008 and it no longer works. When the code gets to the getResponse(), it is giving me a 405 error.
I'm writing to a virtual directory through IIS.
I also tried making it an application and it makes no difference.
We don't have webdav installed/enabled.
I have searched everywhere and can not seem to find the correct solution to allow me to write the file.
I've included the base code that is used to upload the files...
saveLocation.Length = 0;
saveLocation.Append(Path.GetFileName(files[0]));
inStream = File.Open(files[0], FileMode.Open);
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/kw/archive/testFile.pdf");
myWebRequest.ContentType = contentType;
myWebRequest.Method = "put";
//myWebRequest.Headers.Add("action", "put");
myWebRequest.Headers.Add("filename", saveLocation.ToString());
myWebRequest.ContentLength = inStream.Length;
dataToRead = (int)inStream.Length;
outStream = myWebRequest.GetRequestStream();
while (dataToRead > 0) {
if (Response.IsClientConnected) {
length = inStream.Read(buffer, 0, 10000);
outStream.Write(buffer, 0, length);
buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else {
dataToRead = -1;
}
}
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
myWebResponse.Close();
inStream.Close();
outStream.Close();
update: I am currently getting a 405 error.