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:

  1. Select Microsoft Access as your application host in Shared Add-in Wizard.

  2. 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 = null;
context = null;
owner = null;

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


This code sample is available in the following programming languages:


Project Name

Visual C#


Visual Basic.NET



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


  • OneNote 2010 Ribbon AddIn

  • COM AddIn

  • IDTExtensibility

  • OneNote 2010 Object Model


For more information about COM add-in applications to modify User Interface, visit the following MSDN website:

General information about COM AddIns to modify User InterfaceFor more information about compatibility issues for OneNote 2010 and for Visual Studio2010, visit the following MSDN blog:

General information about compatibility issues for OneNote 2010 and for Visual Studio 2010For more information about how to create OneNote 2010 COM add-in applications, visit the following Microsoft websites:

More Information

What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Microsoft website:

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, search for "kbcodefx" together with related keywords on the Microsoft support Web site. Or, visit the following Microsoft website:

All-In-One Code Framework samples

Rapid publishing disclaimer

Microsoft corporation and/or its respective suppliers make no representations about the suitability, reliability, or accuracy of the information and related graphics contained herein. All such information and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information and related graphics, including all implied warranties and conditions of merchantability, fitness for a particular purpose, workmanlike effort, title and non-infringement. You specifically agree that in no event shall Microsoft and/or its suppliers be liable for any direct, indirect, punitive, incidental, special, consequential damages or any damages whatsoever including, without limitation, damages for loss of use, data or profits, arising out of or in any way connected with the use of or inability to use the information and related graphics contained herein, whether based on contract, tort, negligence, strict liability or otherwise, even if Microsoft or any of its suppliers has been advised of the possibility of damages.

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Insiders

Was this information helpful?

What affected your experience?

Thank you for your feedback!