You can read all the details at: Find and Replace Text in OneNote file Programmatically in C#
Last active
December 23, 2021 07:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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