在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
private void button1_Click(object sender, RoutedEventArgs e) { Uri uri = new Uri("ftp://192.168.1.14/"); FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(uri); ftpRequest.Credentials = new NetworkCredential("zz", "123456"); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.UTF8);//
//List<string> directories = new List<string>(); List<string> directories1 = new List<string>(); string line = streamReader.ReadLine(); while (!string.IsNullOrEmpty(line)) { directories.Add(line); string str ; str = line; //C:\\Documents and Settings\\Administrator\\桌面\\1.jpg //str.LastIndexOf(" ");//——得到最后一个“\\”的索引值 //str.Substring(0,str.LastIndexOf("\\")+1)——得到 C:\\Documents and Settings\\Administrator\\桌面\\ //str.Substring(str.LastIndexOf("\\")+1,str.LastIndexOf(".")-str.LastIndexOf("\\")-1);// ——得到 new1 //str.Substring(str.LastIndexOf(" "),str.Length-str.LastIndexOf(" "));// ——得到 x.jpg directories1.Add(str.Substring(str.LastIndexOf(" "),str.Length-str.LastIndexOf(" ")));// ——得到 1.jpg line = streamReader.ReadLine();//读下一串字符 } treeView1.DataContext = directories1; //treeView2.DataContext = directories1; streamReader.Close(); } |
请发表评论