Step 4: Implement the Advanced Code-Based Outlook Solution

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).

Prerequisites

  1. Step 1: Create the BDC Model

  2. Step 2: Create a Cache Subscription

  3. Step 3: Create the Solution Manifest

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.

    newRuntime.Unregister();
    
  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);
        }
        else
        {
            // 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.

Next Steps

Step 5: Package and Deploy the Advanced Code-Based Outlook Solution