Search for and Replace text

VSTO Words

Word.Application wordApp = Application;
        wordApp.Documents.Open("Search and Replace.doc");
        object replaceAll = Word.WdReplace.wdReplaceAll;

        this.Application.Selection.Find.ClearFormatting();
        this.Application.Selection.Find.Text = "find me";

        this.Application.Selection.Find.Replacement.ClearFormatting();
        this.Application.Selection.Find.Replacement.Text = "Found";

        this.Application.Selection.Find.Execute(
            ref missing, ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing, ref missing,
            ref replaceAll, ref missing, ref missing, ref missing, ref missing);

Aspose Words

Document doc = new Document("Search and Replace.doc");
        doc.Range.Replace("find me", "found", false, true);
        doc.Save("Search and Replace.doc");

Download

Last edited Feb 4, 2014 at 5:49 AM by asposemarketplace, version 3