This topic demonstrates how to start an instant messaging (IM) conversation using .NET managed code with Microsoft Lync 2010 SDK.


  • 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 Automation object, create IEnumerable objects to contain URIs, a AutomationModalitySettings enumeration, a Microsoft.Lync.Model.Extensibility . . :: . . AutomationModalities enumeration, and then call the BeginStartConversation method.

To create the IM conversation application

  1. Sign in to Microsoft Lync 2010.

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

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

  4. Add a reference to Microsoft.Lync.Model.

  5. In Form1.cs add the following using statement.

      Copy imageCopy Code
    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
  6. In the Form1 constructor, following the InitializeComponent method, add the following code.

      Copy imageCopy 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>();
    // 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,
    AutomationModalities _ChosenMode =
    // Start the conversation.
    IAsyncResult ar = _Automation.BeginStartConversation(
    	, invitees
    	, _ModalitySettings
    	, null
    	, null);
    //Block UI thread until conversation is started
  7. Build and run the application.

  8. In the conversation window, type message text and then press ENTER.

See Also

Other Resources