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 void UpdateOrCreatePropertyValue(string propertyName, string value) { _document.UpdateOrCreatePropertyValue(propertyName, value); }