How to convert an Interop.Word.Document object to a stream or byte array?

天涯浪子 提交于 2019-12-24 11:34:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!