Friday, August 25, 2006


A Look at GetHierarchy() Part II

The GetHierarchy method has three parameters, startNodeId, hsScope and pbstrHierarchyXmlOut. In part I of A Look at GetHierarchy() I posted some demo code that allowed the user to select the hsScope value and dump OneNote data to the console as Xml. If you compiled and ran the demo app you should have seen different console output based on the scope selected. In this post we will cover the startNodeID.

The startNodeID parameter is type string and represents the ID of an object in OneNote 2007. Each unique object in OneNote 2007 contains a unique ID. If you complied and ran the demo app from the first GetHierarchy post you can see more IDs in the console output then you care to see.

An object id in OneNote 2007 must be unique throughout all objects in OneNote. I have not investigated Live Sharing Sessions to see if "shared" objects are unique, but that's for another post. So what is the best way to create globally unique identifier? Well a GUID of course. Well, that and them some.

Here is an example of an object ID:


It is probably pretty obvious to a developer that the first portion of this ID is a GUID in "registry format". Tacked on is two other pieces of the id that are "undefined" to the developer but an eagle-eyed developer can see a pattern that associates the second bracketed set in the example ({1}) with page-level objects. For those really into Object IDs you can find it defined in the OneNote 2007 Schemas as a simple type of type string with a defined pattern. Hopefully you have something better to do then read Xml schema's for fun.

So now that we know what an object Id is we can start to use it in our calls to GetHierarchy. To get the OneNote "hierarchy" from the very top you pass in a null value as the first demo app in the original A Look at GetHierarchy() post. If you want to start at some node other than the root node simple pass in the appropriate object ID.

For example I used the GetHierarchy demo, passing in null for the startNodeId. Searching in the Xml results I found the Notebook element with the name attribute equal to "OneNote Guide Beta 2". The id attribute for my OneNote installation is {674B715E-9A47-4A2C-9D11-5B7325B27D4B}{1}{B0}. Your OneNote Guide Beta 2's id attribute will be different.

Now I can modify the original demo. I change the startNodeID from null to " {674B715E-9A47-4A2C-9D11-5B7325B27D4B}{1}{B0}". For your demo insert your specific OneNote Guide Beta 2 id. Quotes are required as this is a string value. Below is the modified line in the original demo:

_AppClass.GetHierarchy("{68E92C8A-2C70-434E-8721-5257C952B8D8}{1}{B0}", hs, out oneNoteAsXml);

Now you can run the demo and choose different HierarchyScope values relative to the OneNote Guide Beta 2 Notebook.

Here is an example of using myOneNote Guide Beta 2 Notebook ID and a HierarchyScope of hsSections (Sections in the demo program):

<?xml version="1.0"?>
<one:Notebook xmlns:one="" name="OneNote Guide Beta 2" nickname="OneNote Guide Beta 2" ID="{674B715E-9A47-4A2C-9D11-5B7325B27D4B}{1}{B0}" path="C:\Documents and Settings\OneNoteGuy\My Documents\OneNote Notebooks\OneNote Guide Beta 2" lastModifiedTime="2006-08-25T03:04:48.000Z" color="none"><one:Section name="Getting Started with OneNote" ID="{BDD843A3-B7E2-0FAB-37B6-C7A9F317F049}{1}{B0}" path="C:\Documents and Settings\OneNoteGuy\My Documents\OneNote Notebooks\OneNote Guide Beta 2\Getting Started with" lastModifiedTime="2006-08-25T03:04:48.000Z" color="#D5A4BB"/><one:Section name="More Cool Features" ID="{AD8C801C-F573-0C63-1AC6-624F5676F284}{1}{B0}" path="C:\Documents and Settings\OneNoteGuy\My Documents\OneNote Notebooks\OneNote Guide Beta 2\More Cool" lastModifiedTime="2006-06-19T18:15:48.000Z" color="#FFD869"/></one:Notebook>

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

website statistics