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;

//add this file to the file collection
Microsoft.SharePoint.Client.File newFile = documentFiles.Add(fci);

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

            fs, true);                    

When executing the call to SaveBinaryDirect, I get a 409 (Conflict) exception. What is the problem?

1 Answer 1


The URL given to SaveBinaryDirect needs to be relative to the root site collection. So calling

        fs, true); 

will work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.