Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public MemoryStream GetSingleDocumentBinary(string documentID)
- {
- try
- {
- //Get the document
- List<DocumentLibraryList> documentResult = GetDocuments(documentID);
- //Create the context and get the file info
- System.Net.NetworkCredential sharePointCredentials = new System.Net.NetworkCredential(Username, Password);
- ClientContext sharePointContext = new ClientContext(ServerPath);
- sharePointContext.Credentials = sharePointCredentials;
- var spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(sharePointContext, documentResult[0].DocumentPath);
- //Return document as memoryStream
- MemoryStream resultStream = new MemoryStream();
- spFileInfo.Stream.CopyTo(resultStream);
- return resultStream;
- }
- catch (Exception)
- {
- //log error here with a logger, or call a backup method to do the processing
- throw;
- }
Add Comment
Please, Sign In to add comment