title: WebRequest to PUT file on SharePoint server returns (405) Method Not Allowed
body: <p>I have a sharepoint server on which some files are hosted. </p>
  
  <p>I have some .Net code that creates a WebRequest to GET some of the files. This is is working correctly. </p>
  
  <p>When I try to use similar code to PUT a file at the same location, I'm getting a: </p>
  
  <pre><code>System.Net.WebException: The remote server returned an error: (405) Method Not Allowed on my request.GetResponse();
  </code></pre>
  
  <p>I am not getting any InnerExceptions.</p>
  
  <p>Here is my code:</p>
  
  <pre><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 &gt; 0; i = fileStream.Read(buffer, 0, buffer.Length))
                  requestStream.Write(buffer, 0, i);
  
  
          using (request.GetResponse()) { }
  
          return requestPath;
  </code></pre>
  
  <p>Using the same code (replacing PUT with GET and changing filepath to an existing file) works.</p>
  
  <p>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. </p>