Sharepoint Upload File Error: ‘The remote server returned an error: (409) Conflict’
I’ve been using the following code to upload a file to a Sharepoint document library using the Client Object Model:
- public string Save(string fileName, Stream fileStream)
- {
- string destinationUrl = String.Concat(serverRelativeLibraryUrl, "/", fileName);
- ClientContext clientContext = new ClientContext(webUrl);
- {
- Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, destinationUrl, fileStream, true);
- }
- return destinationUrl;
- }
where
serverRelativeLibraryUrl = String.Concat(webRelativeUrl, libraryName);
But I kept getting the 409 Conflict Error:
ExceptionType: 'WebException' ExceptionMessage: 'The remote server returned an error: (409) Conflict.' StackTrace: '
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.File.SaveBinary(ClientContext context, String serverRelativeUrl, Stream stream, String etag, Boolean overwriteIfExists, SaveBinaryCheckMode checkMode)
at Microsoft.SharePoint.Client.File.SaveBinaryDirect(ClientContext context, String serverRelativeUrl, Stream stream, Boolean overwriteIfExists)
After struggling for a while, I figured out that the problem was the library name. It contained a dash on it, like “My-LibraryName”. When I renamed it without the dash it started working.
The error in the code is how I built the URL. I was using the library name to build the library URL, but it seems that Sharepoint doesn’t like some characters in the URL, so when you create a library called “My-LibraryName”, the URL is actually http://<server>/MyLibraryName, without the dash.