Inconsistent behaviour between Find and Replace

Jun 15, 2011 at 10:52 AM


First of all, thanks for the great library, it helped me out a lot!

I'm searching for a pattern with the FindUniqueByPattern on the document, but it does not return results in the headers & footers. However ReplaceText does replace text in headers and footers.

Without looking in the source code this wasn't really clear, so perhaps an option to include headers/footers in the find methods and replace methods would be more consistent.


Jun 15, 2011 at 1:06 PM
Hi Drake,

thank you for pointing this out, I will make the suggested fix for consistency's sake.

Kind regards,
Apr 2, 2013 at 11:15 AM
Hello Cathal,

I wondered if this feature has been added to any of the subsequent releases? I am currently using v12.

If it hasn't, does anyone have a work around I can use?


Apr 2, 2013 at 4:31 PM
Okay this bit of code searches the header and finds the the Regex text:
DocX doc;
doc = DocX.Load(@"C:\Document.docx");
Regex rxMergeField = new Regex(@"\[(.*?)\]");
string strMergeField = rxMergeField.ToString();
Headers header = doc.Headers;
        if (header.first != null)
            List<string> lstHeaderFields = header.first.FindUniqueByPattern(strMergeField, RegexOptions.IgnoreCase);
You will need to adapt to cater for different odd/even headers...

Hope this is of use