Sample: Use Outlook methods

 

Applies To: Dynamics CRM 2013

This sample code is for Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online. Download the Microsoft Dynamics CRM SDK package. It can be found in the following location in the download package:

SampleCode\CS\Client\Outlook\UseOutlookSdk.cs

SampleCode\VB\Client\Outlook\UseOutlookSdk.vb

Requirements

For more information about the requirements for running the sample code provided in this SDK, see Use the sample and helper code.

Demonstrates

This sample shows how to use the methods available in the Microsoft.Crm.Outlook.Sdk.dll assembly.

Example


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

// Determine if the Outlook client is running
if (outlookService.IsCrmClientLoaded)
{
    if (outlookService.IsCrmDesktopClient)
    {
        // The desktop client cannot go offline
        Console.WriteLine("CRM Client Desktop URL: " +
            outlookService.ServerUri.AbsoluteUri);
        Console.WriteLine("CRM Client state: " +
            outlookService.State.ToString());
    }
    else
    {
        // See if laptop client is offline
        if (outlookService.IsCrmClientOffline)
        {
            Console.WriteLine("CRM Client Offline URL: " +
                outlookService.ServerUri.AbsoluteUri);
            Console.WriteLine("CRM Client state: " +
                outlookService.State.ToString());

            // Take client online
            // NOTE: GoOnline() will automatically Sync up with CRM
            // database, no need to call Sync() manually
            Console.WriteLine("Going Online...");
            outlookService.GoOnline();

            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());

            // Take client offline 
            // NOTE: GoOffline triggers a synchronization of the
            // offline database with the online server.
            // If a sync is not required, you can use SetOffline().
            Console.WriteLine("Going Offline...");
            outlookService.GoOffline();

            Console.WriteLine("CRM Client state: " +
                outlookService.State.ToString());
        }
    }
}

' Set up the CRM Service.  
Dim outlookService As New CrmOutlookService()

' Determine if the Outlook client is running
If outlookService.IsCrmClientLoaded Then
    If outlookService.IsCrmDesktopClient Then
        ' The desktop client cannot go offline
        Console.WriteLine("CRM Client Desktop URL: " & outlookService.ServerUri.AbsoluteUri)
        Console.WriteLine("CRM Client state: " & outlookService.State.ToString())
    Else
        ' See if laptop client is offline
        If outlookService.IsCrmClientOffline Then
            Console.WriteLine("CRM Client Offline URL: " & outlookService.ServerUri.AbsoluteUri)
            Console.WriteLine("CRM Client state: " & outlookService.State.ToString())

            ' Take client online
            ' NOTE: GoOnline() will automatically Sync up with CRM
            ' database, no need to call Sync() manually
            Console.WriteLine("Going Online...")
            outlookService.GoOnline()

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

            ' Take client offline 
            ' NOTE: GoOffline triggers a synchronization of the
            ' offline database with the online server.
            ' If a sync is not required, you can use SetOffline().
            Console.WriteLine("Going Offline...")
            outlookService.GoOffline()

            Console.WriteLine("CRM Client state: " & outlookService.State.ToString())
        End If
    End If
End If

See Also

CrmOutlookService
GoOnline
GoOffline
Extend Microsoft Dynamics CRM 2013 for Outlook
Write custom code for Microsoft Dynamics CRM 2013 for Outlook