Was that I was able to use the same tree control from the Text Importer addin. Fortunately, the code worked "as is" and I was able to copy and paste it from the text importer into my new utility.
There was one change I need to make, though. The Text Importer only lets you choose which notebook you want to use to hold the new section that will get created when the text files get imported. The section color chooser needs you to select a section so that you can alter its color. So the text importer only went as deep as notebooks but what I needed next was going to the section level.
Here’s the code used to get the XML for the notebook level only:
// Get the hierarchy for all notebooks to Notebook level
onApp.GetHierarchy(System.String.Empty, OneNote.HierarchyScope.hsNotebooks, out secHierarchy );
All I had to do to get the sections was change that middle parameter:
// Get the hierarchy for all notebooks to Section level
onApp.GetHierarchy(System.String.Empty, OneNote.HierarchyScope.hsSections , out secHierarchy );
The tree control code I got from MSDN "knew enough" to add the nodes to the notebook level to show the + sign to expand the tree view and add the section names below. That made using this tree view control again very easy.
This also means that if you want to show the pages as well, you only need to change the .hsSections parameter to .hsPages, like this:
// Get the hierarchy for all notebooks to Pages level
onApp.GetHierarchy(System.String.Empty, OneNote.HierarchyScope.hsPages, out secHierarchy );
And the tree view will show the pages. That tree view control is pretty nice and saved me some time – hats off to whoever created it! It made writing these powertoys much easier.
Questions, comments, concerns and criticisms always welcome,