Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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;
        }
    }
Posted 26-Nov-12 19:50pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 184
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Jörgen Andersson 75
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100