Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload to SharePoint with WebDav through proxy fails with HTTP 405

I am trying to upload a file into a SharePoint library by using WebClient and the WebDav .NET library from independentsoft. First I had the problem that the Upload-method returned an exception with HTTP 403. Than I realized that I have to go through a proxy. Now it's returning me HTTP 405. I also used the ClientOM but wasn't able to configure the proxy settings there so I still get a HTTP 403 there.

The code i am using for WebClient and WebDav .NET is the following:

WebClient:

webClient.UseDefaultCredentials = true;
string[] bypassList = { "localhost" };
webClient.Proxy = new WebProxy("proxy", true, bypassList, new NetworkCredential("user", "password"));
try
{
    byte[] response = webClient.UploadFile("http://sharepoint/testBlankSite/testLibrary/TestUpload.txt", "PUT", @"...\Desktop\TestUpload.txt");
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

WebDav .NET

NetworkCredential credential = new NetworkCredential("user", "password");
string[] bypassList = { "localhost" };
WebProxy proxy = new WebProxy("proxy", true, bypassList, new NetworkCredential("user", "password"));
WebdavSession session = new WebdavSession(credential, proxy);

Resource resource = new Resource(session);
try
{
    resource.Upload("http://sharepoint/testBlankSite/testLibrary/TestUpload.txt", @"...\Desktop\TestUpload.txt");
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

Has anyone an idea why this isn't working and how I can solve this?

like image 709
hy13 Avatar asked Nov 11 '22 11:11

hy13


1 Answers

This is a pretty common problem with SharePoint. Check out these links:

SharePoint, WebDAV, and a Case of the 405 Status Codes

SharePoint 2013 - Disable WebDAV use on SharePoint

As @GavinB and @Jeremy mentioned, the alternative is the client-side object model, i.e. Microsoft.SharePoint.Client. This library is just a wrapper and it performs HTTP requests that are similar to the ones you are trying.

like image 180
Keith Avatar answered Nov 14 '22 23:11

Keith