private void listView1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); ListView listView = (ListView)sender; Point targetPoint = listView.PointToClient(new Point(e.X, e.Y)); ListViewItem dropTarget = listView.GetItemAt(targetPoint.X, targetPoint.Y); string target = this.m_Path; if (dropTarget != null && dropTarget.ImageIndex == 0) { target += "/" + dropTarget.Text; } long totalBytes = 0; float transferredBytes = 0; int fileCount = 0; int currentFileNum = 0; foreach (string file in files) { bool IsFile = File.Exists(file); bool IsDir = Directory.Exists(file); if (File.Exists(file)) { FileInfo fi = new FileInfo(file); totalBytes += fi.Length; fileCount++; } else if (Directory.Exists(file)) { RecurseDir(file, ref totalBytes, ref fileCount); } else Logger.Log("Dropped Unknown {0} on {1}", file, target); } //Logger.Log("Total Bytes: {0} Total Files: {1}", totalBytes, fileCount); frmTransferStatus frmStatus = new frmTransferStatus(); frmStatus.Text = "Uploading files to " + m_Session.SessionName; frmStatus.Show(m_DockPanel, DockState.DockBottom); TransferUpdateCallback callback = delegate(bool fileComplete, bool cancelTransfer, FileTransferStatus status) { if (cancelTransfer) { Logger.Log("User requested to Cancel Transfer"); m_Transfer.CancelTransfers(); frmStatus.Close(); LoadDirectory(target); return; } if (fileComplete) { currentFileNum++; transferredBytes += status.BytesTransferred; //Logger.Log("Transfered: {0}/{1} kB {2} of {3} files", transferredBytes, totalBytes / 1024, currentFileNum, fileCount); } frmStatus.UpdateProgress(status, (int)transferredBytes, (int)totalBytes / 1024, currentFileNum, fileCount); if (currentFileNum >= fileCount) { LoadDirectory(target); } }; frmStatus.m_callback = callback; m_Transfer.BeginCopyFiles(files, target, callback); }
private void listView1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); ListView listView = (ListView)sender; Point targetPoint = listView.PointToClient(new Point(e.X, e.Y)); ListViewItem dropTarget = listView.GetItemAt(targetPoint.X, targetPoint.Y); string target = this.m_Path; if (dropTarget != null && dropTarget.ImageIndex == 0) { target += "/" + dropTarget.Text; } long totalBytes = 0; float transferredBytes = 0; int fileCount = 0; int currentFileNum = 0; foreach (string file in files) { bool IsFile = File.Exists(file); bool IsDir = Directory.Exists(file); if (File.Exists(file)) { FileInfo fi = new FileInfo(file); totalBytes += fi.Length; fileCount++; } else if (Directory.Exists(file)) { RecurseDir(file, ref totalBytes, ref fileCount); } else { Log.WarnFormat("Dropped Unknown {0} on {1}", file, target); } } //Logger.Log("Total Bytes: {0} Total Files: {1}", totalBytes, fileCount); frmTransferStatus frmStatus = new frmTransferStatus(); frmStatus.Text = "Uploading files to " + m_Session.SessionName; frmStatus.Show(m_DockPanel, DockState.DockBottom); TransferUpdateCallback callback = delegate(bool fileComplete, bool cancelTransfer, FileTransferStatus status) { if (cancelTransfer) { Log.Info("User requested to Cancel Transfer"); m_Transfer.CancelTransfers(); frmStatus.Close(); LoadDirectory(target); return; } if (fileComplete) { currentFileNum++; transferredBytes += status.BytesTransferred; //Logger.Log("Transfered: {0}/{1} kB {2} of {3} files", transferredBytes, totalBytes / 1024, currentFileNum, fileCount); } frmStatus.UpdateProgress(status, (int)transferredBytes, (int)totalBytes / 1024, currentFileNum, fileCount); if (currentFileNum >= fileCount) { LoadDirectory(target); } }; frmStatus.m_callback = callback; m_Transfer.BeginCopyFiles(files, target, callback); }