I'm trying to save a file to an SP document library using the Client Object Model:
//populate information about the new file, from disk
FileCreationInformation fci = new FileCreationInformation();
fci.Url = fileName;
fci.Content = System.IO.File.ReadAllBytes(filePath);
fci.Overwrite = true;
//load the file collection for the documents in the library
FileCollection documentFiles = docSetFolder.Files;
clientContext.Load(documentFiles);
clientContext.ExecuteQuery();
//add this file to the file collection
Microsoft.SharePoint.Client.File newFile = documentFiles.Add(fci);
clientContext.Load(newFile);
clientContext.ExecuteQuery();
However, it turns out that by default there is a 1MB size limit when uploading files in this way. (Exception: 400 - Bad Request) This blog post details the options for getting around this. It turns out, though, that simply changing the file upload size as specified in the post won't work - the Microsoft.SharePoint library, which is required to do this, only runs on 64-bit CPUs. This is a reasonable assumption when writing server-side code, but this code is supposed to run on client machines. Seems like a pretty big oversight on Microsoft's part.
So I've got to use the second option.
using (ClientContext clientContext = new ClientContext("http://spsite/sites/TestSite/")) {
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
string targetUrl = "testfile.txt";
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext,
targetUrl,
fs, true);
}
}
When executing the call to SaveBinaryDirect, I get a 409 (Conflict) exception. What is the problem?