SharePoint 2016-CSOM-File Upload-via-ClientContext

An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll Additional information: The remote server returned an error: (409) Conflict.

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);

Reason :
• Context can be from Root site or from Sub site, does not make difference.
• Verify that Second parameter to .SaveBinaryDirect( method is right.
• API does not create a folder
• Note: Second parameter is path starting from Root Site, Not Sub site.
So ideally code should be like:
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, “/sites/subsitename /MyDocLibraryName/MyFolderName/Test_FromClientOM.txt”, fileStream, true);

Enjoy SharePoint.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: