Serialize current ActiveDocument from office 2007 add-in

女生的网名这么多〃 提交于 2019-12-29 01:17:33

问题


Im creating a VSTO Office 2007 add-in.

I need to be enable or find a solution where I can save to a webservice with a byte[] instead of hard drive.

So, I open the document by going to a website and clicking on a url, that click send me a Word Document, and I select Open using MS Word 2007.

The document open, and if I check the data I have:

ActiveDocument.Fullname = http://[servername or ip]/[some iis folder]/file.asp?id=353&type=doc`

so I think this is all in memory since I dont have the original file or temp file if exists.

I have no problem from a disk, even if the document is open. How can I do a byte[] from an current ActiveDocument?

I have found a lot of answers, that state that it cannot be done. But I also have a customer that have an old add-in that does the byte[] from a current ActiveDocument.

Can anyone help me.


回答1:


You can convert ActiveDocument to the COM interop IPersistFile to save a copy of the open documents' bytes to a local temp path and then read them back in for sending to your webservice. In Office, you cannot read the bytes from the active document without first saving to disk. See this MSDN blog for reference.

COM.IPersistFile compoundDocument = Application.ActiveDocument as COM.IPersistFile; 
compoundDocument.Save(filePath, false);
byte[] content = File.ReadAllBytes(filePath);


来源:https://stackoverflow.com/questions/12175273/serialize-current-activedocument-from-office-2007-add-in

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