0

I want to read the file attached to a item in share point and store it into a local file.Is it possible?

0

Yes it's possible , you can download a file from list item via CSOM as the following

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 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);
 }
}

Ref : How to download/upload files from/to SharePoint online using CSOM?

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.