private void p_UserChannelCreated(object sender, ChannelCreatedEventArgs e) { Invoke ( new Action ( delegate { SendFileInfo sendFileInfo = (SendFileInfo)e.Data; using (var dialog = new SaveFileDialog()) { dialog.FileName = sendFileInfo.FileName; if (dialog.ShowDialog() != DialogResult.OK) { return; } FormTransferFile form = null; FileStream fileStream = null; try { fileStream = File.Create(dialog.FileName); form = new FormTransferFile(sendFileInfo, fileStream, e.Channel, false); form.Show(); e.CanDisposeChannel = false; } catch (Exception exception) { if (fileStream != null) { fileStream.Dispose(); } if (form != null) { form.Dispose(); } MessageBox.Show(exception.Message); } } } ) ); }
private void listUsers_DragDrop(object sender, DragEventArgs e) { string selectedUser = listUsers.SelectedItem.ToString(); int pos = selectedUser.LastIndexOf(" - "); if (pos > 0) { selectedUser = selectedUser.Substring(0, pos); } string filePath = ((string[])e.Data.GetData("FileDrop"))[0]; FileStream fileStream = null; Stream sendStream = null; FormTransferFile form = null; try { fileStream = File.OpenRead(filePath); SendFileInfo sendFileInfo = new SendFileInfo(selectedUser, Path.GetFileName(filePath), fileStream.Length); sendStream = fConnection.CreateUserChannel(sendFileInfo); form = new FormTransferFile(sendFileInfo, fileStream, sendStream, true); form.Show(); } catch (Exception exception) { if (fileStream != null) { fileStream.Dispose(); } if (sendStream != null) { sendStream.Dispose(); } if (form != null) { form.Dispose(); } MessageBox.Show(exception.Message); } }