void sendFileItem_Click(object sender, RoutedEventArgs e) { IItem item = ((MenuItem)e.Source).Tag as IItem; string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); Dictionary <AutomationModalitySettings, object> _ModalitySettings = new Dictionary <AutomationModalitySettings, object>(); _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hi Serkant, please have a look at this:"); _ModalitySettings.Add(AutomationModalitySettings.Subject, "Sharing File"); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); //_ModalitySettings.Add(AutomationModalitySettings.FilePathToTransfer, @"c:\temp\test.txt"); _ModalitySettings.Add(AutomationModalitySettings.FilePathToTransfer, item.URL); IAsyncResult res = automation.BeginStartConversation(AutomationModalities.InstantMessage | AutomationModalities.FileTransfer, c, _ModalitySettings, null, null); automation.EndStartConversation(res); }
/// <summary> /// Callback invoked when Automation.BeginStartConversation is completed /// </summary> /// <param name="result">The status of the asynchronous operation</param> private void StartConversationCallback(IAsyncResult result) { try { automation.EndStartConversation(result); } catch (LyncClientException lyncClientException) { MessageBox.Show("Call failed."); Console.WriteLine(lyncClientException); } catch (SystemException systemException) { if (IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. MessageBox.Show("Call failed."); Console.WriteLine("Error: " + systemException); } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } }
void shareFileItem_Click(object sender, RoutedEventArgs e) { IItem item = ((MenuItem)e.Source).Tag as IItem; string extension = item.URL.Substring(item.URL.LastIndexOf('.') + 1); Process process = new Process(); switch (extension.ToLower()) { case "dotx": process.StartInfo.FileName = "winword.exe"; process.StartInfo.Arguments = "/t " + item.URL; break; case "doc": case "docx": process.StartInfo.FileName = "winword.exe"; process.StartInfo.Arguments = item.URL; break; case "xls": case "csv": process.StartInfo.FileName = "excel.exe"; process.StartInfo.Arguments = "/r" + item.URL; break; default: process.StartInfo.FileName = "iexplore.exe"; process.StartInfo.Arguments = "-nomerge " + item.URL; break; } process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; process.Start(); while (process.MainWindowHandle == IntPtr.Zero) { System.Threading.Thread.Sleep(100); } string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); AutomationModalities _ChosenMode = AutomationModalities.ApplicationSharing | AutomationModalities.InstantMessage; Dictionary <AutomationModalitySettings, object> _ModalitySettings = new Dictionary <AutomationModalitySettings, object>(); // Add the process Id to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedProcess, process.Id); // Add the main window handle to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedWindow, process.MainWindowHandle); // Adds text to toast and local user IMWindow text-entry control. _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hello Serkant. I would like to share my first running process with you."); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); IAsyncResult res = automation.BeginStartConversation(_ChosenMode, c, _ModalitySettings, null, null); automation.EndStartConversation(res); }