Export (0) Print
Expand All

Use the Methods in the Outlook SDK Assembly

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

This sample shows how to use the methods and properties in the assembly Microsoft.Crm.Outlook.Sdk. Before running this sample, you should start Microsoft Dynamics CRM for Outlook.

This sample code can be found in the following files in the SDK download:

Server\HowTo\CS\Outlook\CRMOutlookService.cs

Example

[C#]
using System;
using CrmSdk;
using Microsoft.Crm.Sdk.Utility;
using Microsoft.Crm.Outlook.Sdk;

namespace Microsoft.Crm.Sdk.HowTo.Outlook
{
   public class CrmOutlookMethodsSample
   {
      public CrmOutlookMethodsSample()
      {

      }
      
      // NOTE:  Before running this sample, you should start the Microsoft Dynamics CRM for Outlook.
      
      public static bool Run(string crmServerUrl, string orgName)
      {
         bool success = true;

         try
         {
            // Set up the CRM Service.  
            CrmOutlookService outlookService = new CrmOutlookService();

            // Determine if the Outlook client is running.
            if (outlookService.IsCrmClientLoaded)
            {
               if (outlookService.IsCrmDesktopClient)
               {
                  // Microsoft Dynamics CRM for Outlook cannot go offline.
                  Console.WriteLine("CRM Client Desktop URL: " + outlookService.ServerUri.AbsoluteUri);
                  Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
               }
               else
               {
                  // See if Microsoft Dynamics CRM for Outlook with Offline Access is offline.
                  if (outlookService.IsCrmClientOffline)
                  {
                     Console.WriteLine("CRM Client Offline URL: " + outlookService.ServerUri.AbsoluteUri);
                     Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
                     
                     // Take Microsoft Dynamics CRM for Outlook online.
                     Console.WriteLine("Going Online...");
                     outlookService.GoOnline();
                     
                     // Sync up with Microsoft Dynamics CRM database.
                     Console.WriteLine("Synchronizing with CRM...");
                     outlookService.Sync(OutlookSyncType.Outlook);

                     Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
                  }
                  else
                  {
                     Console.WriteLine("CRM Client Online URL: " + outlookService.ServerUri.AbsoluteUri);
                     Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
                     
                     // Before going offline, sync up with the Microsoft Dynamics CRM database.
                     Console.WriteLine("Synchronizing with CRM...");
                     outlookService.Sync(OutlookSyncType.Outlook);
                     
                     // Take Microsoft Dynamics CRM for Outlook offline.
                     Console.WriteLine("Going Offline...");
                     outlookService.GoOffline();

                     Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
                  }
               }
            }
         }
         catch (System.Web.Services.Protocols.SoapException)
         {
            // Perform error handling here.
            throw;
         }
         catch (Exception)
         {
            throw;
         }
         
         return success;
      }
   }
}

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft