How to convert an Interop.Word.Document object to a stream or byte array?
I'm trying to upload a word document I have created in memory to Sharepoint 2010 and it looks like the only way to do this is to convert 开发者_运维百科it to a byte array or a stream. Is there anyway I can do this without saving it to disk first?
this link: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/84f1ac3f-f078-4087-a627-351d6bb57173/
suggests that the correct way is to either
- copy the document to the clipboard, then stream the data off the clipboard, or...
- read the document Range's XML.
Cast the document to the IPersistFile interface, and then simply perform the "Save(path,false)" method:
var iPersistFile = (IPersistFile)this.Application.ActiveDocument;
iPersistFile.Save("[path]",false);
All credit goes to these guys:
http://blogs.msdn.com/b/pranavwagh/archive/2008/04/03/how-to-do-a-save-copy-as-in-word.aspx
https://social.msdn.microsoft.com/Forums/vstudio/en-US/84f1ac3f-f078-4087-a627-351d6bb57173/how-to-get-document-content-in-byte-array?forum=vsto
精彩评论