Sharepoint 2010 Client Object Model - Upload Document (409 Conflict)
The issue here was that the site I am uploading to is a subsite, not the root of sharepoint. I don't know if this was a "design" choice or not, but it seems you have to use the root of sharepoint for the ClientContext, at least in this particular case.
Working 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);
}
I was also facing a 409 error while trying to upload a file via the SharePoint 2010 client object model. Make absolutely sure the path you are uploading the file to completely exists. The call will not create any (sub)folders. It does not matter if you're connecting your ClientContext to the root subweb or directly to the subsite as you say. Just make sure you're always feeding the SaveBinaryDirect method the SPSite relative URL of the place to upload to that exists.
For example if you're connecting your ClientContext to http://somesite/sites/subsitename, make sure you're passing to SaveBinaryDirect also the string /sites/subsitename/documents/filename.txt, so relative to the SPSite and not the subsite you're connecting to using your ClientContext.