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.
1: //# [Use the Methods in the Outlook SDK Assembly ]
2: using System;
3: using CrmSdk;
4: using Microsoft.Crm.Sdk.Utility;
5: using Microsoft.Crm.Outlook.Sdk;
6:
7: namespace Microsoft.Crm.Sdk.HowTo.Outlook
8: {
9: public class CrmOutlookMethodsSample
10: {
11: public CrmOutlookMethodsSample()
12: {
13:
14: }
15:
16: // NOTE: Before running this sample, you should start the Microsoft Dynamics CRM for Outlook.
17:
18: public static bool Run(string crmServerUrl, string orgName)
19: {
20: bool success = true;
21:
22: try
23: {
24: // Set up the CRM Service.
25: CrmOutlookService outlookService = new CrmOutlookService();
26:
27: // Determine if the Outlook client is running.
28: if (outlookService.IsCrmClientLoaded)
29: {
30: if (outlookService.IsCrmDesktopClient)
31: {
32: // Microsoft Dynamics CRM for Outlook cannot go offline.
33: Console.WriteLine("CRM Client Desktop URL: " + outlookService.ServerUri.AbsoluteUri);
34: Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
35: }
36: else
37: {
38: // See if Microsoft Dynamics CRM for Outlook with Offline Access is offline.
39: if (outlookService.IsCrmClientOffline)
40: {
41: Console.WriteLine("CRM Client Offline URL: " + outlookService.ServerUri.AbsoluteUri);
42: Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
43:
44: // Take Microsoft Dynamics CRM for Outlook online.
45: Console.WriteLine("Going Online...");
46: outlookService.GoOnline();
47:
48: // Sync up with Microsoft Dynamics CRM database.
49: Console.WriteLine("Synchronizing with CRM...");
50: outlookService.Sync(OutlookSyncType.Outlook);
51:
52: Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
53: }
54: else
55: {
56: Console.WriteLine("CRM Client Online URL: " + outlookService.ServerUri.AbsoluteUri);
57: Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
58:
59: // Before going offline, sync up with the Microsoft Dynamics CRM database.
60: Console.WriteLine("Synchronizing with CRM...");
61: outlookService.Sync(OutlookSyncType.Outlook);
62:
63: // Take Microsoft Dynamics CRM for Outlook offline.
64: Console.WriteLine("Going Offline...");
65: outlookService.GoOffline();
66:
67: Console.WriteLine("CRM Client state: " + outlookService.State.ToString());
68: }
69: }
70: }
71: }
72: catch (System.Web.Services.Protocols.SoapException)
73: {
74: // Perform error handling here.
75: throw;
76: }
77: catch (Exception)
78: {
79: throw;
80: }
81:
82: return success;
83: }
84: }
85: }