In one of the previous tips we have discussed about how we can upload documents in share point 2010 using Client Object Model. In this tips we will be discussing how we can download document from Share Point 2010 using Client Object Model. In order to use ClientContext
we need to add reference to two dll’s to my project i.e. Microsoft.SharePoint.Client.dll
and Microsoft.SharePoint.Client .Runtime.dll
[/code]
Below code snippet used for download the document from Share Point
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; }