I want to save a file from document library to local drive. I am using the Client Object model approach model in development. The following is the code that I use:


But I am not able to understand what is to be passed as a parameter of the type


Note: processSheet is the type of


Please guide.


Save document library file to local file system using CSOM.

using (var clientContext = new ClientContext(url))

     var list = clientContext.Web.Lists.GetByTitle(listTitle);
     var listItem = list.GetItemById(listItemId);
     clientContext.Load(listItem, i => i.File);

     var fileRef = listItem.File.ServerRelativeUrl;
     var filePath = "C:/";
     var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
     var fileName = Path.Combine(filePath,(string)listItem.File.Name);
     using (var fileStream = System.IO.File.Create(fileName))

Answered here. used Microsoft.SharePoint.Client.File.SaveBinaryDirect https://stackoverflow.com/questions/17057074/how-to-download-upload-files-from-to-sharepoint-2013-using-csom

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.


You need to pass stream of Bytes or Byte array which you are supposed to save to the file.

  • Can you please give me an example link or a code block? – Mancy Desaee Aug 6 '15 at 11:18
  • Sure please let me know what kind of data you are storing back to file? is it some string or file data and by client object you mean JS n not C# right ? – Akshay Randive Aug 6 '15 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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