openxml sdk - Open XML SDK: opening a Word template and saving to a different file-name -


this 1 simple thing can't find right technique. want open .dotx template, make changes , save same name .docx extension. can save wordprocessingdocument place it's loaded from. i've tried manually constructing new document using wordprocessingdocument changes made nothing's worked far, tried maindocumentpart.document.writeto(xmlwriter.create(targetpath)); , got empty file.

what's right way here? .dotx file special @ or document far sdk concerned - should copy template destination , open that , make changes, , save? did have concerns if app called 2 clients @ once, if can open same .dotx file twice... in case creating copy sensible anyway... own curiosity still want know how "save as".

i suggest using file.io copy dotx file docx file , make changes there, if works situation. there's changedocumenttype function you'll have call prevent error in new docx file.

            file.copy(@"\path\to\template.dotx", @"\path\to\template.docx");              using(wordprocessingdocument newdoc = wordprocessingdocument.open(@"\path\to\template.docx", true))             {                 newdoc.changedocumenttype(wordprocessingdocumenttype.document);                 //manipulate document....             } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -