Step 4: Implement the Advanced Code-Based Outlook Solution

SharePoint 2010

Last modified: July 06, 2010

Applies to: SharePoint Server 2010

The following steps demonstrate how to create an advanced code-based Microsoft Outlook solution that uses Microsoft Business Connectivity Services (BCS).

To create the Outlook Add-in project

  1. Create a C# Outlook 2010 Add-in project in Microsoft Visual Studio 2010:

    1. In Visual Studio 2010, click File, click New, and then click Project.

    2. In the New Project dialog box, in the Installed Templates pane, expand Visual C#, expand Office, and then select 2010.

    3. In the top bar of the middle pane, from the drop-down list, select .NET Framework 3.5.

    4. From the middle pane, select Outlook 2010 Add-in.

    5. The default project name is OutlookAddIn1. Specify a name for your project if you want a different name.

      You can keep the default values for the location and solution name, or change them if you want different values.

    6. Click OK to create the project.

  2. Perform the following steps to add the following references:

    • Microsoft.BusinessData

    • Microsoft.Office.BusinessApplications.Runtime

    1. In Solution Explorer, locate the References node under your project, right-click this node, and then select Add Reference.

    2. In the Add Reference dialog box, click the Browse tab, and then browse to the desired assembly in the Office installation folder (which typically is %ProgramFiles%\Microsoft Office\Office14\).

    3. Double-click the assembly to add it.

    4. Repeat this process for each assembly.

  3. Add the following using directives at the top of ThisAddIn.cs.

    using BCSRuntime = Microsoft.Office.BusinessApplications.Runtime;
    using System.IO;
  4. Add the following line of code at the start of the ThisAddIn class to declare the global variable for the RuntimeClass.

    public static BCSRuntime.RuntimeClass newRuntime = null;
  5. Add the following code inside the body of the ThisAddIn_StartUp method.

    The solutionOIRNamePath variable points to the solution deployment target folder, which holds all the other solution artifacts (the BDC model and the cache subscriptions).

    string solutionOIRNamePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oir.config");
    newRuntime = new BCSRuntime.RuntimeClass();
    newRuntime.Register(soltionOIRNamePath, new NewRuntimeCallback(), this.Application);
  6. Add the following code inside the body of the ThisAddIn_Shutdown method.

  7. Add a new class named ContosoSalesManagerRuntimeCallback:

    1. In Solution Explorer, right-click the project node, select Add, and then select Class.

    2. In the Add New Item dialog box, type ContosoSalesManagerRuntimeCallback.cs for the name of the class, and then click Add.

  8. In ContosoSalesManagerRuntimeCallback.cs, add the following using directives at the top of the file.

    using BCSRuntime = Microsoft.Office.BusinessApplications.Runtime;
    using System.Windows.Forms;
  9. Append : BCSRuntime.IRuntimeCallback at the end of class ContosoSalesManagerRuntimeCallback.

    This ensures that the class inherits from the IRuntimeCallback interface.

  10. Add the following code inside the body of the ContosoSalesManagerRuntimeCallback class.

    public ContosoSalesManagerRuntimeCallback()
    public void RegistrationComplete(string solutionID, bool success)
        if (null != solutionID && success)
            // Solution registration succeeded.
            // To Do: Trigger any custom events.
            // Example: MessageBox.Show("Solution registration succeeded for solution ID: {0}", solutionID);
            // Solution registration failed.                
            // Example: MessageBox.Show("Solution registration failed for solution ID: {0}", solutionID);                
  11. Build the solution.

    This creates the solution assembly file (for example, OutlookAddIn1.dll in the bin\debug folder if you are using the debug configuration).

  12. At this point, you have the basic template for an advanced code-based solution. You can add your own code to this solution to create customizations such as custom ribbons, task panes, or other user interface customizations.