I have a sharepoint server on which some files are hosted.
I have some .Net code that creates a WebRequest to GET some of the files. This is is working correctly.
When I try to use similar code to PUT a file at the same location, I'm getting a:
System.Net.WebException: The remote server returned an error: (405) Method Not Allowed on my request.GetResponse();
I am not getting any InnerExceptions.
Here is my code:
var requestPath = Path.Combine(serverBasePath, library.GetLibraryPath(), Path.GetFileName(filePath));
var request = WebRequest.Create(requestPath);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.Method = "PUT";
var buffer = new byte[1024];
using (var requestStream = request.GetRequestStream())
using (var fileStream = new FileStream(filePath, FileMode.Open))
for (int i = fileStream.Read(buffer, 0, buffer.Length); i > 0; i = fileStream.Read(buffer, 0, buffer.Length))
requestStream.Write(buffer, 0, i);
using (request.GetResponse()) { }
return requestPath;
Using the same code (replacing PUT with GET and changing filepath to an existing file) works.
Via the Sharepoint Web interface I can upload new files. I have also tried changing the authorization in the parameters to put Full Control for all Authentified Users on this directory.