使用Visual Studio建立一个.aspx文件(Web Forms),例如hovertree.aspx,在页面上加入一个ListBox
代码如下:
- <asp:ListBox runat="server" ID="lbKeleyiFolder" />
那么在页面上显示根目录子文件夹的代码如下:
- string[] m_subKeleyiFolder = Directory.GetDirectories(Server.MapPath("/hvtimg\\"));
- int m_countHovertree = m_subKeleyiFolder.Length;
- for (int i = 0; i < m_countHovertree; i++)
- {
- m_subKeleyiFolder[i] = m_subKeleyiFolder[i].Substring(m_subKeleyiFolder[i].LastIndexOf("\\") + 1);
- }
- lbKeleyiFolder.DataSource = m_subKeleyiFolder;
- lbKeleyiFolder.DataBind();