Small chat about OneNote GUIDs

I was reading the The Unknown OneNote Guy's Blog on his/her post about A Look at GetHierarchy() Part II and there was something that stood out that I wanted comment on that I haven't mentioned before, here is what I read:

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.

I haven't talked much about GUIDs in this blog and how they will be unique, etc. First of all almost all items in OneNote have unique IDs, otherwise we could export them and reimport them into a page unless they were unique. So here are items that have hierarchy IDs:

  • Notebooks
  • Section Groups
  • Sections
  • Pages

These items will be unique for a given OneNote session; if I have 4 notebooks open each will have a GUID that will not appear anywhere else in the hierarchy. Additionally other items have an object ID which is an ID for something on the page, here are items that have object IDs:

  • Outlines
  • Images
  • InkDrawings
  • Embedded Files
  • Media files
  • Etc.

Almost any item on the page will have something which is unique on that page, however OneNote makes no guarantees that these items will be unique across all of the notebooks/sections/pages. That is why for certain methods you need both a hierarchyID and an objectID, like:

  • GetHyperlinkTo where you need to specific both a high-level object and something lower on the page, if you want a hyperlink to that item on the page.
  • NavigateTo, much like GetHyperlinkTo this will allow you to navigate to something else and you can just go to a page and leave the objectID parameter null or you can pass in an objectID as well and that will tell OneNote to navigate to the right place (this is fixed post B2TR so you won't see this in B2TR).

One last comment about GUIDs, they are unique for an individual session in OneNote BUT they are not in the files. That means that across two computers you will have two different GUIDs and if you close a notebook and then reopen the notebook it will have a new GUID. There are some GUIDs stored in the file but what happens is OneNote takes that GUID and combines it with the GUID of your cache and that becomes the GUID for your notebook. There is some other crazy math so that they can easily look @ GUIDs and see what they are for, but the most important point here is that the GUIDs will change when you open and close a notebook.