Im using WinForms and i try to open MS Word document (with some help info) on button click from my form
My code :
using Microsoft.Office.Interop.Word;
Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application();
Document document = ap.Documents.Open(Resource1.sign_full);
My .docx file is sign_full.docx. I added it to my project Resource1.resx file. Then If I press button1 i get
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) error in "ap.Documents.Open(Resource1.sign_full)" line
Is there any way to open it using Documents.Open? Or shoud i use somthing else?
The answer could be found here: How to open embedded resource word document?
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.sign_full.docx);
application.Documents.Open(fileName);
Then when you've detected Word has been closed, delete the file:
File.Delete( fileName );
User contributions licensed under CC BY-SA 3.0