.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Download the document from Share Point

Posted By:abhays       Posted Date: August 31, 2014    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Download the document from Share Point

Below code explains how to download the document from SharePoint.

public Stream DownloadDocument(string siteURL, string documentName)
ListItem item = GetDocumentFromSP(documentName);
if (item != null)
using (ClientContext clientContext = new ClientContext(siteURL))
FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, item ["FileRef"].ToString());            
return fInfo.Stream;
return null;
private static ListItem GetDocumentFromSP(string documentName)
//This method is discussed above i.e. Get List Item Collection from SharePoint Document List
ListItemCollection listItems = GetListItemCollectionFromSP("FileLeafRef", documentName, "Text", 1);
return (listItems != null && listItems.Count == 1) ? listItems[0] : null;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend