Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/96e35f16c7b847479832665a28f2340e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/96e35f16c7b847479832665a28f2340e to your computer and use it in GitHub Desktop.
C# Find and Replace Text in OneNote file Programmatically in .NET
// Specify search and replace string
Dictionary<string, string> replacements = new Dictionary<string, string>();
replacements.Add("2. Get organized", "New Text Here");
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
// Get all RichText nodes
IList<RichText> textNodes = oneFile.GetChildNodes<RichText>();
foreach (RichText richText in textNodes)
{
foreach (KeyValuePair<string, string> kvp in replacements)
{
if (richText != null && richText.Text.Contains(kvp.Key))
{
// Replace text of a shape
richText.Text = richText.Text.Replace(kvp.Key, kvp.Value);
}
}
}
// Save updated one note file
oneFile.Save(dataDir + "ReplaceTextOnAllPages.one" , SaveFormat.One);
// Specify find and replace text
Dictionary<string, string> replacements = new Dictionary<string, string>();
replacements.Add("voice over", "voice over new text");
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
IList<Page> pageNodes = oneFile.GetChildNodes<Page>();
// Get all RichText nodes
IList<RichText> textNodes = pageNodes[0].GetChildNodes<RichText>();
foreach (RichText richText in textNodes)
{
foreach (KeyValuePair<string, string> kvp in replacements)
{
if (richText != null && richText.Text.Contains(kvp.Key))
{
// Replace text of a shape
richText.Text = richText.Text.Replace(kvp.Key, kvp.Value);
}
}
}
// Save to any supported file format
oneFile.Save(dataDir + "ReplaceTextOnParticularPage.one", SaveFormat.One);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment