Asp. NET how to display files using the TreeView _ Practical Tips

Source: Internet
Author: User

The example in this article tells you how ASP.net uses the TreeView to display files, and is a very useful technique. Share to everyone for your reference. The implementation methods are as follows:

The TreeView is commonly used in asp.net, and here's a detailed account of how you use the TreeView to display files.

1. Add the TreeView control First:

<asp:treeview id= "Driverinfoview" runat= "imageset=" Xpfileexplorer "ontreenodepopulate=" DriverInfoView_ Treenodepopulate "> 
     
</asp:TreeView> 

2. When the page is loaded, write down the following code:

protected void Page_Load (object sender, EventArgs e) 
{ 
    foreach (DriveInfo driverinfo in Driveinfo.getdrives ()) c3/>{ 
      TreeNode newNode = new TreeNode (); 
      newnode.expanded = false; 
      Newnode.populateondemand = true; 
      Newnode.value = Driverinfo.name; 
 
      if (Driverinfo.isready) 
      { 
        Newnode.text = driverinfo.name + "(" + Driverinfo.volumelabel + ")"; 
      } 
      else 
      { 
        Newnode.text = driverinfo.name + "(Not ready yet)"; 
      } 
      THIS.DRIVERINFOVIEW.NODES.ADD (NewNode); 
    } 
 

3. Set events for the TreeView node:

protected void Driverinfoview_treenodepopulate (object sender, TreeNodeEventArgs e) 
{ 
    DirectoryInfo dictinfo = New DirectoryInfo (e.node.value); 
 
    foreach (DirectoryInfo directory in Dictinfo.getdirectories ()) 
    { 
      TreeNode newNode = new TreeNode (); 
      newnode.expanded = false; 
      Newnode.populateondemand = true; 
      Newnode.text = Directory. Name; 
      Newnode.value = Directory. FullName; 
      E.node.childnodes.add (NewNode); 
    } 
 
    foreach (FileInfo FileInfo in Dictinfo.getfiles ()) 
    { 
      TreeNode newNode = new TreeNode (); 
      Newnode.text = Fileinfo.name; 
      Newnode.value = Fileinfo.fullname; 
      E.node.childnodes.add (NewNode); 
    } 


It is believed that the example mentioned in this article has certain reference value for the ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.