This topic demonstrates how to start an instant messaging (IM) conversation using .NET managed code with Microsoft Lync 2010 SDK.
Prerequisites
-
Microsoft Lync 2010
-
Microsoft Windows Server 2003, Microsoft Windows Server 2008, Microsoft Windows XP, Microsoft Windows Vista, or Microsoft Windows 7
-
Microsoft Visual Studio 2008 or Microsoft Visual Studio 2010
-
Microsoft .NET Framework 3.5 SP1
-
Microsoft Lync 2010 SDK
Creating the IM Conversation Application
To start an IM conversation, get a
To create the IM conversation application
-
Sign in to Microsoft Lync 2010.
-
In Visual Studio development system, create a new application. The application can be any type of managed code application. In this procedure you create a Windows Forms application.
-
Select .NET Framework 3.5 or 4.0 as the target framework. For more information, see the MSDN topic How to: Target a Specific .NET Framework.
-
Add a reference to Microsoft.Lync.Model.
-
In Form1.cs add the following using statement.
Copy Code using Microsoft.Lync.Model; using Microsoft.Lync.Model.Extensibility;
-
In the Form1 constructor, following the InitializeComponent method, add the following code.
Copy Code // Create the major API automation object. Automation _Automation = LyncClient.GetAutomation(); // Create a generic List object to contain a contact URI. // Ensure that a valid URI is added. List<string> inviteeList = new List<string>(); inviteeList.Add("elise@contoso.com"); // Create text for the first IM message. string firstIMText = "hello"; // Create a generic Dictionary object to contain conversation setting objects. Dictionary<AutomationModalitySettings, object> _ModalitySettings = new Dictionary<AutomationModalitySettings, object>(); AutomationModalities _ChosenMode = AutomationModalities.InstantMessage; _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, firstIMText); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); // Start the conversation. IAsyncResult ar = _Automation.BeginStartConversation( _ChosenMode , invitees , _ModalitySettings , null , null); //Block UI thread until conversation is started _Automation.EndStartConversation(ar);
-
Build and run the application.
-
In the conversation window, type message text and then press ENTER.