4

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:

processSheet.SaveBinary(FileSaveBinaryInformation);

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

FileSaveBinaryInformation

Note: processSheet is the type of

Microsoft.SharePoint.Client.File

Please guide.

3 Answers 3

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(list);
     clientContext.Load(listItem, i => i.File);
     clientContext.ExecuteQuery();


     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))
     {                  
          fileInfo.Stream.CopyTo(fileStream);
     }
}
1

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

0
0

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

3
  • 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.