This topic demonstrates how to transfer a file in an instant messaging (IM) conversation using .NET code with Microsoft Lync 2010 SDK.


For a list of prerequisites, see Walkthrough: Start an Instant Message Conversation .

Creating the IM Conversation Application

To create the file transfer application

  1. Sign in to Microsoft Lync 2010.

  2. In Microsoft Visual Studio development system, create a new 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.Comunicator.Model.

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

      Copy imageCopy Code
    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
  6. At the top of the Formclass add the following declarations.

      Copy imageCopy Code
    // Create the major UI Automation objects.
    Automation _Automation = LyncClient.GetAutomation();
    // Create a dictionary object to contain AutomationModalitySettings
    data pairs.
    Dictionary<AutomationModalitySettings, object>
    _ModalitySettings = new Dictionary<AutomationModalitySettings,
  7. In the Form1_Load event add the following code.

      Copy imageCopy Code
    AutomationModalities _ChosenMode =
    AutomationModalities.FileTransfer |
    // Store the file path as an object using the generic List class.
    string myFileTransferPath = string.Empty;
    // Edit this to provide a valid file path.
    myFileTransferPath = @"C:\myFolder\myFile.txt";
    // Create a generic List object to contain a contact URI.
    String[] invitees = {""}
    //Adds text to toast and local user IMWindow text entry control.
    "Hello Elise. I would like to send you my text file.");
    //Add file transfer conversation context type
    // Start the conversation.
    IAsyncResult ar =  _Automation.BeginStartConversation(
    	, invitees
    	, _ModalitySettings
    	, null
    	, null);
    //Block UI thread until conversation is started.
  8. Build and run the application.

  9. Enter a contact name and then click OK. The conversation window appears with a link to the specified file. The remote user gets a conversation invitation with an option to accept the text file.

See Also

Other Resources