asp.net获取站点根目录下子目录的名称

本文介绍如何使用ASP.NET WebForms中的ListBox控件显示指定目录下的子文件夹列表,并提供了一个具体的示例代码,包括如何获取目录信息及绑定到ListBox。

使用Visual Studio建立一个.aspx文件(Web Forms),例如hovertree.aspx,在页面上加入一个ListBox
代码如下:

Html代码   收藏代码
  1. <asp:ListBox runat="server" ID="lbKeleyiFolder" />  

 

那么在页面上显示根目录子文件夹的代码如下:

C#代码   收藏代码
  1. string[] m_subKeleyiFolder = Directory.GetDirectories(Server.MapPath("/hvtimg\\"));  
  2.   
  3. int m_countHovertree = m_subKeleyiFolder.Length;  
  4. for (int i = 0; i < m_countHovertree; i++)  
  5. {  
  6. m_subKeleyiFolder[i] = m_subKeleyiFolder[i].Substring(m_subKeleyiFolder[i].LastIndexOf("\\") + 1);  
  7. }  
  8.   
  9. lbKeleyiFolder.DataSource = m_subKeleyiFolder;  
  10. lbKeleyiFolder.DataBind();  

 

HoverTree系统源码下载http://hovertree.codeplex.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值