Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

Streamline your Word document editing with the Syncfusion .NET Word Library (DocIO). In C#, you can find and replace text with dynamic elements, including images, hyperlinks, paragraphs, tables, or even an entire document. This functionality operates independently of Microsoft Word and interop dependencies. Refine your searches using options for case-sensitive and whole-word matches.

Find and replace in Word document using C#

This example code shows how to find and replace text in a Word document using the Syncfusion .NET Word Library with just a few lines of C# code.

  1. //Add the required namespaces
  2. using Syncfusion.Pdf.Parsing;
  3. using Syncfusion.Pdf;
  4. using Syncfusion.DocIO;
  5. using Syncfusion.DocIO.DLS;
  6. //Load an existing Word document
  7. using FileStream inputDocumentStream = new FileStream("Template.docx", FileMode.Open, FileAccess.ReadWrite);
  8. using WordDocument document = new WordDocument(inputDocumentStream, FormatType.Docx);
  9. //Replace all occurrences of the word "Cyles" with "Cycles"
  10. document.Replace("Cyles", "Cycles", true, true);
  11. //Save the Word document
  12. using FileStream outputDocumentStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite);
  13. document.Save(outputDocumentStream, FormatType.Docx);

Key features of the Find functionality

Find text

Find text in a Word document based on a specific pattern using a regular expression (regex) or a normal string. You can search the entire document or within a specific paragraph.

Casing and whole words

Refine the find operation by matching the casing or whole word for precise results.

Find first

Find only the first occurrence of a piece of text in a Word document.

Find all

Find all the occurrences of a text length in all parts of a Word document, including the body, header, footer, shapes, comments, footnotes, and endnotes.

Find next

While splitting the PDF document, the file size is optimized by removing unused resources without altering any content.

Find multiline text

Find the first or next occurrence of a text that extends across several paragraphs.

Features of the Replace functionality

Replace text

Perform a find and replace operation for the text in a Word document and track the total number of replacements made. You can find a static text or specific pattern using a regular expression (regex).

Replace first

Replace only the first occurrence of the specified text in a Word document.

Replace with document

Replace the searched text with document elements such as paragraphs, tables, and content controls while maintaining the source formatting.

Replace with document elements

Replace the searched text with document elements such as paragraphs, tables, and content controls while maintaining the source formatting.

Replace with selection

Find and retrieve text with formatting (bold, highlight) for replacement in occurrences of other placeholders in a Word document, maintaining that formatting.

Replace multiline text

Replace all text occurrences spanning multiple paragraphs with the replacement text or document elements.

Features of Find elements

Find the element by properties

Locate the first Word document element that matches a specified property or a collection of properties. For example, find a picture by its alternative text or a chart by its title and type.

Find all elements by properties

Find all elements that match a specified property or a collection of properties. For example, find all fields of a specific type or all content controls with a specific title and tag.

Explore find and replace references

Check our blog and knowledge base articles to improve your efficiency with find and replace functionalities in Word documents.

Explore 7 Useful Ways to Find and Replace Text in Word Documents

Blog

Explore 7 Useful Ways to Find and Replace Text in Word Documents Using C#

Find and replace text with a hyperlink in Word documents using C#

Knowledge base

Find and replace text with a chart in a Word document

Knowledge base

How to find and replace text with a chart in a Word document

Find and replace text with a Table of Contents (TOC) in a Word document

Knowledge base

How to find and replace text with a Table of Contents (TOC) in a Word document

Replace text in a Word document with HTML using C#

Knowledge base

How to replace text in a Word document with HTML using C#

Find and replace text inside a table in a Word document

Knowledge base

How to find and replace text inside a table in a Word document

Syncfusion .NET Word Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.

Frequently Asked Questions

Yes, you can customize the find functionality in the .NET Word library (DocIO) to search the text based on criteria such as case sensitivity and whole-word matching.

Yes. Besides finding and highlighting, you can format the found text with options such as bold, underline, font size, and more.

Yes, like finding text in a Word document, the .NET Word Library (DocIO) offers options to find Word document elements based on their properties.

Yes, you can replace text with Word document elements such as images, hyperlinks, tables, and more.

Yes, using the .NET Word Library (DocIO), you can find and replace text in a specific paragraph.

You can access it through the Syncfusion.DocIO.Net.Core NuGet package. The documentation provides detailed code samples, facilitating seamless integration.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion® reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, View, and edit Word documents in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.

Scroll up icon
Chat with us