How to open embedded resource word document?

99封情书 提交于 2019-12-02 08:44:58

Word can only open files that exist in the filesystem, it cannot work entirely from-memory.

Do something like this:

String fileName = Path.GetTempFileName();
File.WriteAllBytes( fileName , Properties.Resources.MyDoc );
application.Documents.Open( fileName  );

Then when you've detected Word has been closed, delete the file:

File.Delete( fileName );

It might be an idea (for performance reasons) to embed the Word document as an Embedded Resource instead of a Byte[] array within a resx file, like so:

Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream resourceStream = thisExe.GetManifestResourceStream("MyDoc.docx");
// copy the stream to a new FileStream, then open Word as-before
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!