问题
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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/4820017/how-to-convert-an-interop-word-document-object-to-a-stream-or-byte-array