Add Multi-line support to OpenXmlPowerTools’ SearchAndReplacer

When editing Microsoft Word files in a web-environment like ASP.NET, the OpenXML API is a must!
I recently needed to create a new document based on a template.
There are to my knowledge 2 ways of doing this:

  • Creating the whole document with code
  • Or creating some template tags and replacing them

Since the latter is easier on the designing part, I chose that one.
I added placeholders in the form of {CustomerName} and {CustomerAddress} to my file and replaced those with the correct values.

Instead of writing a search and replace routine all by myself, I used the awsome OpenXmlPowerTools for this. There is a SearchAndReplacer class in it that does a super job at it.
There is only 1 downside. When your replacement text is multi-line, it comes out at a single line.

This bothered me, since the {CustomerAddress} is obviously more than 1 line of text, so I wrote in the multi-line support.

SearchAndReplacerDownload the modified SearchAndReplacer.cs file.