Created
March 19, 2023 23:15
-
-
Save atcarter714/7ad976d2351596687e3e6bdf42d97609 to your computer and use it in GitHub Desktop.
Read a OneNote hierarchy in C# ....
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
static void Main(string[] args) { | |
// OneNote 2013 Schema namespace. | |
string strNamespace = "http://schemas.microsoft.com/office/onenote/2013/onenote"; | |
string outputXML; | |
Application onApplication = new Application(); | |
onApplication.GetHierarchy(null, HierarchyScope.hsSections, out outputXML); | |
// Load a new XmlDocument. | |
XmlDocument xmlDoc = new XmlDocument(); | |
xmlDoc.LoadXml(outputXML); | |
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); | |
nsmgr.AddNamespace("one", strNamespace); | |
// Search for the section named "Sample_Section". | |
XmlNode xmlNode = xmlDoc.SelectSingleNode("//one:Section[@name='Sample_Section']", nsmgr); | |
// Prompt for a new section title. | |
System.Console.Write("Please enter a new title for the section: "); | |
string input = System.Console.ReadLine(); | |
xmlNode.Attributes["name"].Value = input; | |
// Update the section with the new title. | |
onApp.UpdateHierarchy(xmlNode.OuterXml); | |
System.Console.Write("Done!\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a handy snippet I wanted to save and import programmatically for examples ...