Hello,
I have sorted uploading and deleting files from a SharePoint 2013 Document Library (using CSOM), but I am having problems with the following code to allow users to open / save files.
public void DownloadDocument(string siteURL, string libraryName, string fileName)
{
using (ClientContext clientContext = new ClientContext(siteURL))
{
var list = clientContext.Web.Lists.GetByTitle(libraryName);
clientContext.Load(list.RootFolder);
clientContext.ExecuteQuery();
var fi = new FileInfo(fileName);
var source = String.Format("{0}/{1}/{2}", list.RootFolder.ServerRelativeUrl, null, fi.Name);
var spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, source);
using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
{
spFileInfo.Stream.CopyTo(fs);
}
}
}How can I prompt the user to open / save the selected file (this should be the standard browsers download file prompts)? If they open the file it should open in the default application. The files could be any type (.xlsx, .pdf, .docx, .txt, etc.)
Many thanks
Duane
hj