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

838 Views Asked by At

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?

1

There are 1 best solutions below

1
On

Use LoadFromStream method.

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