SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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

        fs, true); 

will work.

share|improve this answer
Thanks! ............. – Eric Herlitz Feb 3 '12 at 20:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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