public IDocument OpenFile(string cacheName, string serverRelativeUrl) { if (serverRelativeUrl == null) { WordOM.Document nDoc = _document.Application.Documents.Add(); var document = new OfficeDocument(nDoc); return(document); } using (var clientContext = new ClientContext(Settings.Default.SharePointContextUrl)) { string temp = Path.GetTempFileName(); FileInformation fileInformation = File.OpenBinaryDirect(clientContext, serverRelativeUrl); Stream stream = fileInformation.Stream; using (FileStream output = System.IO.File.OpenWrite(temp)) { stream.CopyTo(output); } ObjectCache cache = MemoryCache.Default; cache.Add(cacheName, string.Empty, new CacheItemPolicy()); WordOM.Document d = _document.Application.Documents.Add(temp); d.UpdateOrCreatePropertyValue(Constants.WordDocumentProperties.CacheName, cacheName); System.IO.File.Delete(temp); var document = new OfficeDocument(d); return(document); } }
public IDocument OpenFile(string serverRelativeUrl) { using (var clientContext = new ClientContext(Properties.Settings.Default.SharePointContextUrl)) { var temp = System.IO.Path.GetTempFileName(); FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, serverRelativeUrl); var stream = fileInformation.Stream; using (FileStream output = System.IO.File.OpenWrite(temp)) { stream.CopyTo(output); } var d = _document.Application.Documents.Add(temp); var doc = new OfficeDocument(d); System.IO.File.Delete(temp); return(doc); } }