如何在treeview asp.net C#中获取客户端文件系统目录

嗨,我正在开发一个基于Web的ftp客户端应用程序,我想获取客户端文件系统目录并将它们填充到树视图中我尝试此代码,但它将给出我的应用程序运行的系统(服务器)的目录,我希望当任何用户通过浏览器访问我的应用程序我想加载用户文件系统目录。

这是我试过的代码:

private void fillTree() { DirectoryInfo directory; string sCurPath = ""; // clear out the old values TreeView2.Nodes.Clear(); // loop through the drive letters and find the available drives. foreach (char c in driveLetters) { sCurPath = c + ":\\"; try { // get the directory informaiton for this path. directory = new DirectoryInfo(sCurPath); // if the retrieved directory information points to a valid // directory or drive in this case, add it to the root of the // treeView. if (directory.Exists == true) { TreeNode newNode = new TreeNode(directory.FullName); TreeView2.Nodes.Add(newNode); // add the new node to the root level. getSubDirs(newNode); // scan for any sub folders on this drive. } } catch (Exception doh) { lblStatus.Text = doh.Message; } } } private void getSubDirs(TreeNode parent) { DirectoryInfo directory; try { // if we have not scanned this folder before if (parent.ChildNodes.Count == 0) { directory = new DirectoryInfo(parent.ValuePath); foreach (DirectoryInfo dir in directory.GetDirectories()) { TreeNode newNode = new TreeNode(dir.Name); parent.ChildNodes.Add(newNode); } } // now that we have the children of the parent, see if they // have any child members that need to be scanned. Scanning // the first level of sub folders insures that you properly // see the '+' or '-' expanding controls on each node that represents // a sub folder with it's own children. foreach (TreeNode node in parent.ChildNodes) { // if we have not scanned this node before. if (node.ChildNodes.Count == 0) { // get the folder information for the specified path. directory = new DirectoryInfo(node.ValuePath); // check this folder for any possible sub-folders foreach (DirectoryInfo dir in directory.GetDirectories()) { // make a new TreeNode and add it to the treeView. TreeNode newNode = new TreeNode(dir.Name); node.ChildNodes.Add(newNode); } } } } catch (Exception doh) { lblStatus.Text = doh.Message; // Console.WriteLine(doh.Message); } } private string fixPath(TreeNode node) { string sRet = ""; try { sRet = node.ValuePath; int index = sRet.IndexOf("\\\\"); if (index > 1) { sRet = node.ValuePath.Remove(index, 1); } } catch (Exception doh) { Console.WriteLine(doh.Message); } return sRet; } 

任何人都可以帮助我正确执行此任务。

正如其他人所说,您的服务器端代码无法读取客户端的文件系统。

您最好的选择是编写和签署Java小程序(允许已签名的小程序访问文件系统)并将小程序嵌入到网页中。 ActiveX也是一种选择,但它仅限于Internet Explorer。

您显示的代码在服务器上运行。 您无法访问那里的客户端文件夹。

要做到这一点,您需要一个客户端运行脚本或程序和访问

通常,浏览器不允许访问文件系统。 看看这个问题,找出如何做到这一点: 浏览器应用程序和本地文件系统访问

您无法访问客户端文件系统并使用ASP .NET或JavaScript填充它。

也许你可以试试JavaScript。 它将允许您获取驱动器中的文件列表。

   
Named :

Path :

 
Search Result