Post Code Snippets Here

Mar 19, 2008 at 12:53 AM
here's one to start everybody off :)

To use the OM

1) Download and build the OM.
2) This should produce two dll's (OneNoteCore.dll and OneNoteFrameWork.dll). Add reference to your project

To Get page Content

using Microsoft.Office.OneNote; ( to use the OM)
using System.Xml.Linq ( This is necessary since the OM uses Linq to return page content)

{ Side Note: Those who don't know LINQ should carry on and not give up at this point since it is very similar to the XML DOM model }

XDocument pageConent = OneNoteApplication.Current.GetPageContent(pageID, Microsoft.Office.OneNote.Interop.PageInfo.All);


XDocument is the LINQ form of XMLDocument :)

The second parameter is the type of content you want, as specified in the OneNoteApi. You don't need to remember all that since intellisense will help.

To create a pageID from a String :-
OneNoteObjectID pageID = OneNoteObjectID.Parse("{D7F1AF1B-3C34-41D1-8227-840B5C444D15}{1}{B0}");

Thats it. This should get you the page content in XDocument form. (There is no need to create a OneNoteApplication you would normally do if accessing the API directly, The OM takes care of it.)

Ani
Developer
Mar 19, 2008 at 3:18 PM
You are not supposed to use the OneNoteApplication class, which is a very thin wrapper around the COM interface. Instead, you should use the OneNoteHierarchy class to get to the notebooks, sections and pages.
Mar 19, 2008 at 7:18 PM

jachymko wrote:
You are not supposed to use the OneNoteApplication class, which is a very thin wrapper around the COM interface. Instead, you should use the OneNoteHierarchy class to get to the notebooks, sections and pages.


How do I get the page Content using the OneNoteHierarchy Class? I thought there was something wrong with GetPageContent returning an XDocument instead of a OneNotePage, so I guess there must be another way to get it? I just can't seem to find it. I think most users would just go with the OneNoteApplication class ( atleast till the OM is complete) due to the familiarity with the OneNote API and lack of documentation.

Ani
Developer
Mar 20, 2008 at 10:52 AM
Edited Mar 20, 2008 at 10:53 AM
OneNoteHierarchy.Current.Notebooks[0].Sections[0].Pages[0].Outlines[0].Elements[0]

the OneNoteCore project is really only a wrapper to make the OneNote API look more .net-ish (ie. return values instead out params, nice exceptions instead of error codes, OneNoteObjectId and XDocument instead of strings, and so on)

the OneNoteFramework poject implements the real object model -- ie. Pages, Sections, Outlines, and so on