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.
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.
- //Add the required namespaces
- using Syncfusion.Pdf.Parsing;
- using Syncfusion.Pdf;
- using Syncfusion.DocIO;
- using Syncfusion.DocIO.DLS;
- //Load an existing Word document
- using FileStream inputDocumentStream = new FileStream("Template.docx", FileMode.Open, FileAccess.ReadWrite);
- using WordDocument document = new WordDocument(inputDocumentStream, FormatType.Docx);
- //Replace all occurrences of the word "Cyles" with "Cycles"
- document.Replace("Cyles", "Cycles", true, true);
- //Save the Word document
- using FileStream outputDocumentStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite);
- document.Save(outputDocumentStream, FormatType.Docx);
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.
Refine the find operation by matching the casing or whole word for precise results.
Find only the first occurrence of a piece of text in a Word document.
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.
While splitting the PDF document, the file size is optimized by removing unused resources without altering any content.
Find the first or next occurrence of a text that extends across several paragraphs.
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 only the first occurrence of the specified text in a Word document.
Replace the searched text with document elements such as paragraphs, tables, and content controls while maintaining the source formatting.
Replace the searched text with document elements such as paragraphs, tables, and content controls while maintaining the source formatting.
Find and retrieve text with formatting (bold, highlight) for replacement in occurrences of other placeholders in a Word document, maintaining that formatting.
Replace all text occurrences spanning multiple paragraphs with the replacement text or document elements.
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 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.
Check our blog and knowledge base articles to improve your efficiency with find and replace functionalities in Word documents.
Knowledge base
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
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.
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.