// 加载文件目录 private void LoadFiles(String filepath) { // 查询数据 FileListVO fileList = new FileListVO(new List <FtpFile>()); try { List <FtpFile> files = ftpClient.getFileList(filepath); fileList = new FileListVO(files); } catch (Exception e) { Console.Error.Write(e); MessageBox.Show("FTP连接异常:" + e.Message); return; } // 显示数据 fileListView.Clear(); this.fileListView.BeginUpdate(); fileListView.View = View.Details; fileListView.FullRowSelect = true; fileListView.LargeImageList = fileList.largeIconList; fileListView.SmallImageList = fileList.smallIconList; this.fileListView.Columns.Add("文件名", 240, HorizontalAlignment.Left); this.fileListView.Columns.Add("大小", 120, HorizontalAlignment.Right); this.fileListView.Columns.Add("修改时间", 120, HorizontalAlignment.Left); foreach (FileInfoVO info in fileList.list) { model.FileInfo f = info.fileInfo; ListViewItem item = new ListViewItem(); item.ImageIndex = fileList.list.IndexOf(info); item.Text = f.name; item.SubItems.Add(f.isDirectory ? null : FileUtils.GetString(f.size)); item.SubItems.Add(f.lastWriteTime.ToString()); item.Tag = f; this.fileListView.Items.Add(item); } this.fileListView.EndUpdate(); }
private void ItemDoubleClick(object sender, EventArgs e) { SelectedListViewItemCollection items = fileListView.SelectedItems; if (items.Count > 0) { ListViewItem item = items[0]; model.FileInfo fileInfo = (model.FileInfo)item.Tag; if (fileInfo.isDirectory) { LoadFiles(fileInfo.fullname); } else { DownloadFile(fileInfo.fullname); } } }