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.

3 Answers 3


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


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? Commented Aug 6, 2015 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 ? Commented Aug 6, 2015 at 11:23
  • Please give us example of Word file with content in it
    – Jahangeer
    Commented Apr 21, 2020 at 7:19

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.