Using GetSpecialLocation with the OneNote API

I just got the following question from someone and I thought I would respond with a blog post. Actually I had this _exact_ same question just a few weeks ago; here is the question:

Using OneNote Interop I use GetSpecialLocation with the SpecialLocation.slUnfiledNotesSection parameter and receive what appears to be the full path for the Unfiled Notes section. I then attempt to create a new page using the value I received from GetSpecialLocation. I receive a 0x80042004 which appears to be section does not exist. Yet the .one file is at the location returned by the GetSpecialLocation call.

This is a great question and I would like to explain things:

  • The GetSpecialLocation allows you to find the items that are open in OneNote but might not appear in the OneNote hierarchy because these items (Unfiled Notes, backup folder & default notebook location) can all appear outside of your notebooks.
  • GetSpecialLocation always returns a path which you cannot use with the other OneNote API calls, since the other calls always use the OneNote GUIDs (unique IDs).

Instead you will want to do the following:

  • GetSpecialLocation to get the string
  • Call OneNote to open the location and you will then have the ID

The code looks like this:

OneNote.Application onApp = new OneNote.Application();
string unfiledSectionPath;
onApp.GetSpecialLocation(OneNote.SpecialLocation.slUnfiledNotesSection, out unfiledSectionPath);
string unfiledSectionID;
onApp.OpenHierarchy(unfiledSectionPath, null, out unfiledSectionID, OneNote.CreateFileType.cftNone);

Now you have section ID in the variable unfiledSectionID. You can then use that to call CreateNewPage or use it in the XML that you create yourself. If you have questions please post in the comments or contact me.

Comments (1)

  1. says:

    Hello Daniel,

    I am trying to access the values of the out parameters in JavaScript. The OneNote methods will just not return the values.

    I Tried working with this:

    function valueObject() {

    this.value = null;


    var oneNote = new ActiveXObject("OneNote.Application");

    var pbstrNotebookID = new valueObject();

    var outValue = oneNote.OpenHierarchy("D:\Note", "", pbstrNotebookID, 1);

    By the guidelines, it should return the notebook ID to the "pbstrNotebookID variable.

    But I find it to be "null" always 🙁

    Can you please tell me why this is not possible with JavaScript?

Skip to main content