Search code examples
onenoteonenote-api

How do you get the current page? [Trying to create a simple OneNote Addin that adds text to the current page]


As the title says I am trying to create a OneNote addin that just adds some text to the current page (in your OneNote Desktop App).

I've had a look at the API and I could add in the text to the Pages XML then update the page using UpdatePageContent()... but I can't see anything to give you the page you are currently looking at?

I'm sorry if this is obvious, or if there is a way to just edit the page without he need of the API... I've spent few days researching OneNote Addin examples but only just managed to actually get a button showing in the ribbon!

Any advice or guidance would be greatly appreciated.


Solution

  • The answer if you are using the Desktop version of OneNote is this:

    string thisNoteBook = oneNote.Windows.CurrentWindow.CurrentNotebookId;
    string thisSection = oneNote.Windows.CurrentWindow.CurrentSectionId;    
    string thisPage = oneNote.Windows.CurrentWindow.CurrentPageId;
    

    These will get you the ID's of the page currently active, from there you can use

    oneNote.GetPageContent(thisPage, out xmlPage);
    

    or

    oneNote.GetHierarchy(thisNoteBook, HierarchyScope.hsSections, out HieracyXML);
    

    etc.


    If anyone reading this needs any further help just send me a message.