Search text in Microsoft OneNote sections

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

To search a keyword in Microsoft OneNote sections Search(String) method is used. This method returns the collection of SearchResult objects. For details, see Search Text.

Here are the steps to search a keyword in Microsoft OneNote section:

  • Instantiate Parser object for the initial section;
  • Call Search(string) method and obtain the collection of SearchResult objects;
  • Iterate through the collection and get the position and text.
Warning
Search(String) method returns null value if search isn’t supported for the section. For example, text extraction isn’t supported for Zip archive. Therefore, for Zip archive Search(String) method returns null. For empty Microsoft OneNote section Search(String) method returns an empty collection.

The following example shows how to find a keyword in Microsoft OneNote section:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search a keyword:
    IEnumerable<SearchResult> sr = parser.Search("page number");
   
    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index and found text:
        Console.WriteLine(string.Format("At {0}: {1}", s.Position, s.Text));
    }
}

Search(String, SearchOptions) is used for the advanced search in Microsoft OneNote sections - like search with regular expressions, search by pages etc. SearchOptions parameter is used to customize a search.

Here are the steps to search with a regular expression in Microsoft OneNote section:

The following example shows how to search with a regular expression in Microsoft OneNote section:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search with a regular expression with case matching
    IEnumerable<SearchResult> sr = parser.Search("page number: [0-9]+", new SearchOptions(true, false, true));
    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index and found text:
        Console.WriteLine(string.Format("At {0}: {1}", s.Position, s.Text));
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document parser App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.