Guest User

Untitled

a guest
Jul 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1.         public MemoryStream GetSingleDocumentBinary(string documentID)
  2.         {
  3.             try
  4.             {
  5.                 //Get the document
  6.                 List<DocumentLibraryList> documentResult = GetDocuments(documentID);
  7.    
  8.                 //Create the context and get the file info
  9.                 System.Net.NetworkCredential sharePointCredentials = new System.Net.NetworkCredential(Username, Password);
  10.                 ClientContext sharePointContext = new ClientContext(ServerPath);
  11.                 sharePointContext.Credentials = sharePointCredentials;
  12.    
  13.                 var spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(sharePointContext, documentResult[0].DocumentPath);
  14.    
  15.                 //Return document as memoryStream
  16.                 MemoryStream resultStream = new MemoryStream();
  17.                 spFileInfo.Stream.CopyTo(resultStream);
  18.                 return resultStream;
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 //log error here with a logger, or call a backup method to do the processing
  23.                 throw;
  24.             }
Add Comment
Please, Sign In to add comment