树视图格式的文件详细信息 [英] file details in tree view format

查看:62
本文介绍了树视图格式的文件详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个Web应用程序,其中我必须以xml格式访问客户端计算机上的文件详细信息,其中包括所有详细信息,例如createdate,modified(包括所有文件和文件夹以及文件夹内的文件),并显示为GUI.date中的treeview格式

1.以xml格式获取响应并以树视图格式显示.

i have to create and web application in which i have to access the file details on the client machine with all details like createdate,modified(including all file and folders and file inside the folders also) in xml format,and show in treeview format in a GUI.date

1.getting response in xml format and showing in tree view format.

推荐答案

1.读取文件内容并构建所需的xmlString

1. Read file content and build the desired xmlString

string line;
string xmlString = "";

// Read the file line by line.
System.IO.StreamReader file =
   new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
   // Build your xmlString here
    // you can use line.Split() to seperate the data
    // Add xml tags and build your xml in the desired format.

}

file.Close();



2.将您的xmlString传递给下面的populateTreeView方法以构建树视图.



2. Pass your xmlString to populateTreeView method below to build your treeview.

private void populateTreeview(string xmlString)
        {
                    
                try
                {

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.LoadXml(xmlString);
                    
                    //adding root node
                    TreeView1.Nodes.Clear();
                    TreeView1.Nodes.Add(new
                      TreeNode(xDoc.DocumentElement.Name));
                    TreeNode tNode = new TreeNode();
                    tNode = (TreeNode)TreeView1.Nodes[0];
                    
                    addTreeNode(xDoc.DocumentElement, tNode);
                    
                    TreeView1.ExpandAll();
                }                
                catch (Exception ex) //General exception
                {
                    
                }                
        }
        
        void addTreeNode(XmlNode xmlNode, TreeNode treeNode)
        {
            XmlNode xNode;
            TreeNode tNode;
            XmlNodeList xNodeList;
            if (xmlNode.HasChildNodes) 
            {
                xNodeList = xmlNode.ChildNodes;
                for (int x = 0; x <= xNodeList.Count - 1; x++)
                //Loop through the child nodes
                {
                    xNode = xmlNode.ChildNodes[x];
                    treeNode.ChildNodes.Add(new TreeNode(xNode.Name));
                    tNode = treeNode.ChildNodes[x];
                    addTreeNode(xNode, tNode);
                }
            }
            else 
                treeNode.Text = xmlNode.OuterXml.Trim();
        }


这篇关于树视图格式的文件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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