如何获取FTP服务器的所有文件并在GRIDVIEW中显示?

时间:2015-06-29 13:38:31

标签: c# winforms datagridview

如何从WebRequestMethods.Ftp.ListDirectoryDe​​tails中提取文件名,文件大小,日期

注意: - 我完成了ListView .. 我的编码

private void btnListFiles_Click(object sender, EventArgs e)
 {
  string[] filenames = GetFilesDetailList();
 dataGridView1.Rows.Clear();
  foreach (string filename in filenames)
 {
 dataGridView1.Rows.Add(filename)
 }
}

    private string[] GetFilesDetailList()
    {

            ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            WebResponse response = ftp.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string line = reader.ReadLine();
            while (line != null)
            {
                result.Append(line);
                result.Append("\n");
                line = reader.ReadLine();
            }

            result.Remove(result.ToString().LastIndexOf("\n"), 1);
            reader.Close();
            response.Close();
            return result.ToString().Split('\n');
            //MessageBox.Show(result.ToString().Split('\n'));
        }

0 个答案:

没有答案