This article describes an All-In-One Code Framework sample that is available for download. The code sample demonstrates how to develop a Microsoft OneNote 2010 COM add-in application that implements the
IRibbonExtensibility interface. The add-in application supports to customize the ribbon by implementing the
IRibbonExtensibility interface. This code sample also introduces how to use the OneNote 2010 object model .
Difficulty level

Download information
To download this code sample, click one of the following links:
Technical overview
Create a shared add-in application for OneNote 2010
Because
Shared Add-in Wizard does not contain a Microsoft OneNote option, to create a shared add-in application for OneNote 2010, follow these steps:
- Select Microsoft Access as your application host in Shared Add-in Wizard.
- Modify the setup project registry HKCU to the following registry subkey:
[HKEY_CURRENT_USER\Software\Microsoft\Office\OneNote\AddIns\CSOneNoteRibbonAddIn.Connect]"LoadBehavior"=dword:00000003"FriendlyName"="OneNoteRibbionAddIn""Description"="OneNote2010 Ribbon AddIn Sample"
Inherit the IDTExtensibility interface to custom the ribbon control for OneNote
To custom the ribbon control for OneNote, run the following code to make the connect class inherit the
IRibbonExtensibility interface, and then implement the
GetCustomUI method:
/// <summary>
/// Loads the XML markup from an XML customization file
/// that customizes the Ribbon user interface.
/// </summary>
/// <param name="RibbonID">The ID for the RibbonX UI</param>
/// <returns>string</returns>
public string GetCustomUI(string RibbonID)
{
return Properties.Resources.customUI;
}
Custom icon and implement features of buttons for the ribbon control
Run the following code to implement the
OnGetImage and
ShowForm methods in the customUI.xml file:
/// <summary>
/// Implements the OnGetImage method in customUI.xml
/// </summary>
/// <param name="imageName">the image name in customUI.xml</param>
/// <returns>memory stream contains image</returns>
public IStream OnGetImage(string imageName)
{
MemoryStream stream = new MemoryStream();
if (imageName == "showform.png")
{
Resources.ShowForm.Save(stream, ImageFormat.Png);
}
return new ReadOnlyIStreamWrapper(stream);
}
/// <summary>
/// show Windows Form method
/// </summary>
/// <param name="control">Represents the object passed into every
/// Ribbon user interface (UI) control's callback procedure.</param>
public void ShowForm(IRibbonControl control)
{
OneNote.Window context = control.Context as OneNote.Window;
CWin32WindowWrapper owner =
new CWin32WindowWrapper((IntPtr)context.WindowHandle);
TestForm form = new TestForm(applicationObject as OneNote.Application);
form.ShowDialog(owner);
form.Dispose();
form = null;
context = null;
owner = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
Use the OneNote 2010 object model to get the title for an OneNote page
Add Microsoft OneNote 14.0 Object Library reference, and then set the
Embed Interop Type property to
False:
/// <summary>
/// Get the title of the page
/// </summary>
/// <returns>string</returns>
private string GetPageTitle()
{
string pageXmlOut = GetActivePageContent();
var doc = XDocument.Parse(pageXmlOut);
string pageTitle = "";
pageTitle = doc.Descendants().FirstOrDefault().Attribute("ID").NextAttribute.Value;
return pageTitle;
}
Technology category
Office development
Languages
This code sample is available in the following programming languages:
Language | Project Name |
---|
Visual C# | COneNoteRibbonAddIn |
Visual Basic.NET | VBOneNoteRibbonAddIn |
Prerequisites
To run this code sample, you must install the following products:
- Microsoft Visual Studio 2010
- Microsoft Visual Studio Tools for Microsoft Office 2010
- Microsoft OneNote 2010
Tags
- OneNote 2010 Ribbon AddIn
- COM AddIn
- IDTExtensibility
- OneNote 2010 Object Model
References
For more information about COM add-in applications to modify User Interface, visit the following MSDN website:
For more information about compatibility issues for OneNote 2010 and for Visual Studio2010, visit the following MSDN blog:
For more information about how to create OneNote 2010 COM add-in applications, visit the following Microsoft websites: