SharePoint SharePoint Client Object Model - Download Document (409 Conflict)

I am using the SP2010 client object model to upload to the document library following Microsoft's directions here: http://msdn.microsoft.com/en-us/library/ee956524.aspx#SP2010ClientOMOpenXml_Uploading

I encounter HTTP status code 409 (conflict) while executing the following code.

var clientContext = new ClientContext("http://myservername/sites/subsitename") { Credentials = LogonCredentials }; using (var fileStream = new FileStream(@"C:\Temp\Test.txt", FileMode.Open)) { Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/MyDocLibraryName/Test_FromClientOM.txt", fileStream, true); } 

What am I doing wrong?

+7
c # sharepoint-2010
source share
4 answers

The problem was that the site I am loading is a sub site and not the sharepoint root. I don’t know whether it was a design choice or not, but it seems you need to use the sharepoint root for the ClientContext, at least in this particular case.

Work code:

 var clientContext = new ClientContext("http://myservername") { Credentials = LogonCredentials }; using (var fileStream = new FileStream(@"C:\Temp\Test.txt", FileMode.Open)) { Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/sites/subsitename/MyDocLibraryName/Test_FromClientOM.txt", fileStream, true); } 
+8
source share

I also encountered error 409 when trying to upload a file using the SharePoint 2010 client object model. Verify that the path that you are loading into the file exists. The call will not create any (auxiliary) folders. It doesn’t matter if you connect your ClientContext to the root website or directly to the sub-site, as you say. Just make sure you always feed the SaveBinaryDirect method with the relative SPSite URL of the download location to the existing one.

For example, if you connect your ClientContext to http: // somesite / sites / subsitename , make sure that you pass SaveBinaryDirect the line /sites/subsitename/documents/filename.txt as well, therefore it is relative to SPSite and not to the child site you are connecting to using your ClientContext.

+7
source share

Soledad Pano has a blog post Sharepoint file upload error: 'Remote server returned error: (409) Conflict that helped me

I realized that the problem was in the name of the library. It contained a dash on it, for example, "My-LibraryName". When I renamed it without a dash, it started working

+1
source share

In my case, the file was uploaded using SaveBinaryDirect to the library with version control turned on. If the file is not registered, any subsequent attempts to download a newer version will result in error 409. Remember to check after downloading when version control is turned on.

  var clientContext = (ClientContext)file.Context; destinationWebContext.Load(destinationList, d => d.ParentWebUrl); destinationWebContext.Load(destinationList, d => d.RootFolder.ServerRelativeUrl); clientContext.Load(file, f => f.ServerRelativeUrl); clientContext.Load(file, f => f.Name); if (clientContext.HasPendingRequest) clientContext.ExecuteQueryRetry(); if (destinationWebContext.HasPendingRequest) destinationWebContext.ExecuteQueryRetry(); var location = string.Format("{1}/{2}", destinationList.ParentWebUrl, destinationList.RootFolder.ServerRelativeUrl, file.Name); var fileInfo = File.OpenBinaryDirect(clientContext, file.ServerRelativeUrl); File.SaveBinaryDirect(destinationWebContext, location, fileInfo.Stream, overwrite); File newFile = destinationWebContext.Web.GetFileByServerRelativeUrl(location); newFile.CheckIn("Checked in by provisioning service", Microsoft.SharePoint.Client.CheckinType.MajorCheckIn); destinationWebContext.ExecuteQuery(); 
0
source share

All Articles