在树状视图中显示文件图标(文件类型) [英] Showing icon of files (type of file) in tree view

查看:80
本文介绍了在树状视图中显示文件图标(文件类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have used below code for structure of folders and files in server but I need icon of file (type of file) in tree view structure.





<pre>protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo(Server.MapPath("~/Document/Detail Engineering/"));

            // output the directory into a node
            TreeNode RootNode = OutputDirectory(RootDir, null);

            // add the output to the tree
            TreeView1.Nodes.Add(RootNode);
            TreeView1.CollapseAll();
        }
    }

    TreeNode OutputDirectory(System.IO.DirectoryInfo directory, TreeNode parentNode)
    {
        // validate param
        if (directory == null) return null;

        // create a node for this directory
        TreeNode DirNode = new TreeNode(directory.Name);

        // get subdirectories of the current directory
        System.IO.DirectoryInfo[] SubDirectories = directory.GetDirectories();

        // output each subdirectory
        for (int DirectoryCount = 0; DirectoryCount < SubDirectories.Length; DirectoryCount++)
        {
            OutputDirectory(SubDirectories[DirectoryCount], DirNode);
        }

        // output the current directories files
        System.IO.FileInfo[] Files = directory.GetFiles();

      for (int FileCount = 0; FileCount < Files.Length; FileCount++)
       {
           string sFullname = directory.FullName;
           string sStr = sFullname + "\\" + Files[FileCount].Name;
           System.IO.FileInfo file = new System.IO.FileInfo(sStr);
           DirNode.ChildNodes.Add(new TreeNode(Files[FileCount].Name, Files[FileCount].Name));
          
           TreeNode subnode = new TreeNode(Files[FileCount].Name);
           string test = subnode.ValuePath;
          subnode.NavigateUrl = sStr;
          subnode.SelectAction = TreeNodeSelectAction.Select;

           


        }

        // if the parent node is null, return this node
        // otherwise add this node to the parent and return the parent
        if (parentNode == null)
        {
            return DirNode;
        }
        else
        {
            parentNode.ChildNodes.Add(DirNode);
            return parentNode;
        }
    }

推荐答案

您只需要为Treeview模板应用一些CSS:

以下是一些修改treeview样式的好例子:

带有模板的ASP.NET AJAX TreeView控件 [ ^ ]

http://www.dotnetfunda.com/forums/thread7380-treeview-with-custom- css.aspx [ ^ ]


[ ^ ]

我相信,如果您还需要更多..,请尝试使用Google谷歌搜索如何使用Trees修改Treeview控件.

希望这会有所帮助!

快乐编码:)
You just need to apply some CSS for treeview template:

Below are few good examples to modify the treeview style:

An ASP.NET AJAX TreeView control with templates[^]

http://www.dotnetfunda.com/forums/thread7380-treeview-with-custom-css.aspx[^]


[^]

I believe if you need more.. just try googling on how to modify treeview control using css.

Hope this helps!

Happy Coding :)


这篇关于在树状视图中显示文件图标(文件类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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