Jul 31, 2015 01:21 AM|Nan Yu|LINK
Hi Eswaran ,
This should be done by using MS Word API. Becuase, the file may contains images, text formatting. So, we need to do this without affecting the images and text formatting.
According to your description ,I would recommend you using the Open XML SDK to achieve your requirement .With the library, you can do the following to replace text from a Word document:
// To search and replace content in a document part.
public static void SearchAndReplace(string document)
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("Hello world!");
docText = regexText.Replace(docText, "Hi Everyone!");
using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
You could refer to link below for more details and demo: