C#: Online Guide
How To: Word SDK
Text Search
  |  
Home ›› XDoc.Word ›› C# Word: Text Search

C# Word - Search and Find Text in Word


Learn How to Search Text in PDF Document and Obtain Text Content and Location Information




Overview



RasterEdge XDoc.Word for .NET allows C# programmers to integrate text search functionality into their Word document management application. To be specific, using mature C#.NET APIs, programmers can achieve following aspects.


Related .net document control helps:
c# asp.net sharepoint document viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
view file asp.net: View multiple document formats in ASP.NET, MVC, Ajax, Azure using C# control
c# asp.net pdf document viewer: ASP.NET PDF Document Viewer in C#: view, annotate, redact Adobe PDF files online in ASP.NET
c# asp.net document annotation: ASP.NET Document Annotation Control: text comment, drawing on files online using ASP.NET component
c# asp.net text document viewer: C# HTML5 Viewer: Load, View, Convert, Annotate and Edit OpenOffice, CSV and Text file
asp.net doc file viewer: ASP.NET Office Word Document Viewer: view MS Office Word files online using C# in ASP.NET web applications
asp.net convert pdf using c#: ASP.NET Convert PDF Control: Convert, export PDF to Word, HTML, Tiff files in C# ASP.NET


Easy to search and find text content and get its location details


Allow to search defined Word page or the whole document


Support searching Word file with various search options, like searching whole Word document, ignoring the letter case, matching string, etc.




C# PDF: Example of Finding Text in Word



Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.Imaging.Basic.Codec.dll


Using namespaces:


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Word;


  using RasterEdge.Imaging.Basic.TextSearch;


The following C# coding example illustrates how to perform Word text searching function in your .NET project, including setting search option, creating search result and saving the result.http://localhost




internal static void TestSearch(String fileName, String matchString, String cacheFile)
{

// Set search options.
RESearchOption option = new RESearchOption();
option.SetMatchString(matchString);
option.WholeWord = true;
option.IgnoreCase = true;
option.ContextExpansion = 30;

// It will create a cach file if your PDF document is never been searched before. 
if (!File.Exists(fileName))
{
BaseDocument document = getBaseDocument(TestFilePath.InputFilePath + fileName);
document.CacheSearchInfo(TestFilePath.InputFilePath + cacheFile);
}

// Create search result.
SearchResult sResult = new SearchResult();

// Search and store the result in the entity of search structure.
BaseDocument.Search(TestFilePath.InputFilePath + cacheFile, option, sResult);
}

private static BaseDocument getBaseDocument(String filePath)
{
BaseDocument document = null;
if (filePath.EndsWith(".pdf"))
document = new PDFDocument(filePath);
else if (filePath.EndsWith(".docx"))
document = new DOCXDocument(filePath);
else if (filePath.EndsWith(".xlsx"))
document = new XLSXDocument(filePath);
else
{}
return document;
}