2

To upload a file using File.SaveBinaryDirect you have to know the server relative URL of the document library you're working with.

Example from MSDN :-

ClientContext clientContext = new ClientContext("http://intranet.contoso.com");
using (FileStream fileStream = new FileStream("NewDocument.docx", FileMode.Open))
{
   ClientOM.File.SaveBinaryDirect(clientContext,
            "/Shared Documents/NewDocument.docx", fileStream, true);
}

How can you determine a Document Libraries url?

1 Answer 1

6
docLib = Context.Web.Lists.GetByTitle("Your Doclib Name");

Context.Load(docLib);
Context.Load(docLib.RootFolder);
Context.ExecuteQuery();

string serverRelativeUrl = docLib.RootFolder.ServerRelativeUrl;
1
  • There has got to be a better way to do this. I'm trying to upload a document FAST. That's why I'm using SaveBinaryDirect. This is SLOOOOOOOOOOOW. Commented Jul 5, 2016 at 21:21

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.