简体   繁体   中英

Is there a better way to load a docx file from embedded resource?

I'm recreating an old abandoned program that i created when i was learning c# which outputs a word file with the information from a form. The program extract the embedded resource which is template.docx located in Res folder to C:\\ClearanceResource\\template.docx then will be load by the program again using:

dox.LoadFromFile(@"C:\ClearanceResource\template.docx");

is there a better way to do this like getting the string location path of the embedded resource and using it in the dox.Loadfromfile(someStringPath) so that i dont need to create an instance of the file per run?

Use LoadFromStream method.

Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("template.docx");
Document dox = new Document();
dox.LoadFromStream(stream, FileFormat.Docx);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM