This project has moved. For the latest updates, please go here.

Replace a string placeholder in word document

Dec 26, 2013 at 5:46 AM
In my asp.net application I have add following code to replace placeholders with some value in word document.
 using (DocX dc = DocX.Load(Server.MapPath("~/Uploads/") + "Sample Quality Report - v1.docx"))
                {
                    dc.ReplaceText("[Client Name]", "test client",false,System.Text.RegularExpressions.RegexOptions.Multiline);
                    dc.ReplaceText("[Category Name]", "test category", false, System.Text.RegularExpressions.RegexOptions.Multiline);
                    dc.ReplaceText("[Url]", "test url", false, System.Text.RegularExpressions.RegexOptions.Multiline);

}
However the above code doesn't work for the 10th page, it doesn't replace any values on that page

need advice
Dec 26, 2013 at 7:32 AM
Edited Dec 26, 2013 at 7:35 AM
Above code for replace function doesnt work in the 9th page of the Word document: Download
Developer
Jan 1, 2014 at 6:59 PM
I've used this simple example to try and reproduce problem with 10th page but it replaces the text for 20+ pages without a problem. Is there anything special in your document?
    static void HelloWorldReplaceTextExample()
    {
        Console.WriteLine("\tHelloWorldReplaceTextExample()");

        // Create a new document.
        using (DocX document = DocX.Create(@"docs\Hello World Replace Example.docx"))
        {
            for (int i = 0; i <= 1000; i++)
            {
                // Insert a Paragraph into this document.
                Paragraph p = document.InsertParagraph();

                // Append some text and add formatting.
                p.Append("Hello World!^011Hello World!").Font(new FontFamily("Times New Roman"));
            }
            document.ReplaceText("Hello", "Test");

            // Save this document to disk.
            document.Save();
            Console.WriteLine("\tCreated: docs\\Hello World Replace Example.docx\n");
        }
    }