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

Help: Replacing text using Bookmark

Apr 15, 2015 at 9:53 PM
In my template doc., I already set the bookmark in the specified text/word. Now, what I'm trying to do is I want to change/replace that text using the embedded bookmark in it. Is it possible? Please Help me.

Best Regards,
-iRevenge
Apr 16, 2015 at 10:29 AM
public void CreateSampleDocument()
{

    string filetemplate = @"E:\Template\Sample.docx";
    string fileNameTemplate = @"E:\Output\Conformation-Letter-{0}-{1}.docx";
    string StaffName = "Hari";
    string outputFileName = string.Format(fileNameTemplate, StaffName, DateTime.Now.ToString("dd-MMM-yyyy"));
    DocX  letter = DocX.Load(filetemplate);
    letter.InsertAtBookmark(StaffName, "STAFFNAME");
    letter.InsertAtBookmark("7-Mar-2015", "CONFDATE");
    letter.InsertAtBookmark("O-1", "CADRE");          
    Process.Start("WINWORD.EXE", "\"" + outputFileName + "\"");
}
Marked as answer by MadBoy on 4/16/2015 at 7:06 AM
Aug 8, 2015 at 9:04 PM
Hi,

this sample only insert text before the new bookmark. Is it also possible to replace the bookmark text?

Regards
Christian
Aug 10, 2015 at 5:17 AM
Use this

letter.Text.Replace("oldtext", "newtext");