Walkthrough: Transfer a File (Lync 2010 SDK)

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

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.

    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
  6. At the top of the Form class add the following declarations.

    // 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, object>();
  7. In the Form1_Load event add the following code.

    AutomationModalities _ChosenMode = AutomationModalities.FileTransfer | AutomationModalities.InstantMessage;
    // 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 = {"elise@contoso.com"}
    // Adds text to toast and local user IMWindow text entry control.
    _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hello Elise. I would like to send you my text file.");
    _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
    // Add file transfer conversation context type
    _ModalitySettings.Add(AutomationModalitySettings.FilePathToTransfer, myFileTransferPath);
    // 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.