如何获得在树状asp.net C#客户端文件系统目录 [英] How to get client file system directories in treeview asp.net C#

查看:111
本文介绍了如何获得在树状asp.net C#客户端文件系统目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发我想获得客户端文件系统的目录,并将它们填充到一个树视图我试试这个code一个基于Web的FTP客户端应用程序,但我的应用程序运行时它会给系统(服务器)的目录,我想,当任何用户通过浏览器accesss我的申请,我想负荷用户的文件系统的目录。

Hi i am developing a webbased ftp client application i want to get client file system directories and populate them into a tree view i try this code but it will give directories of the system (server) where my application is running , i want that when any user accesss my application through a browser i want load users filesystem directories.

这是code这是我尝试:

this is the code which i tried:

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;
        }

任何一个可以帮助我如何正确地执行此任务。

Can any one help me how to perform this task correctly.

推荐答案

正如所说别人,你的服务器端code无法读取客户端的文件系统。

As said by others, your server-side code can't read client's file system.

您最好的选择是编写并签署Java小程序(据我所知签名的Applet被允许访问文件系统),并嵌入小程序的网页。 ActiveX是也是一种选择,但它仅限于IE浏览器。

Your best option is to write and sign a Java applet (afaik signed applets are allowed to access the file system) and embed the applet to the web page. ActiveX is also an option, but it's limited to Internet Explorer.

这篇关于如何获得在树状asp.net C#客户端文件系统目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆