Hi, I want to create new DOCX file by reading DOCX template (it's content is already replaced)

Posted by ruwan Kumara on Stack Overflow See other posts from Stack Overflow or by ruwan Kumara
Published on 2010-04-09T03:35:50Z Indexed on 2010/04/09 3:43 UTC
Read the original article Hit count: 537

Filed under:
|
|
|

Up to now code is read the template and replace with new values and finally replace the docx file with new values. Can any one please tell me how to save the replaced docx file in diffrent name?.

My code is bellow.

using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true)) { string docText = null; using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream())) { docText = sr.ReadToEnd(); }

            Regex regexText = new Regex("#ApplicationCompleteDate#");
            docText = regexText.Replace(docText,DataHolding.ApplicationCompleteDate);

            regexText = new Regex("#ApplicantPrivateAddress#");
            docText = regexText.Replace    (docText,UserDataHolding.ApplicantPrivateAddress);


       using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream   (FileMode.Create)))
            {
                sw.Write(docText);
            }
        }

If any one help me with this creating new docx file by changing above code, it will be very helpful for me.

thank You.

© Stack Overflow or respective owner

Related posts about creating

Related posts about new