<%@ Import Namespace="System.IO"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myDirInfo,myFolderInfo As DirectoryInfo
Dim arrFolderInfo As Array
Dim tnode as TreeNode
myDirInfo = New DirectoryInfo(Server.MapPath("MyFiles/"))
arrFolderInfo = myDirInfo.GetDirectories
For Each myFolderInfo In arrFolderInfo
tnode = New TreeNode(myFolderInfo.Name)
'กำหนดรูป folder อันนี้สมมติว่าอยู่ที่ images/ ถ้าไม่มีรูปก็ไม่ต้องใส่ก็ได้
tnode.ImageUrl = "~/images/folder.gif"
TreeView1.Nodes.Add(tnode);
Next myFolderInfo
myDirInfo = Nothing
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - List Directory</title>
</head>
<body>
<form runat="server">
<asp:TreeView ID="TreeView1" runat="server"></asp:TreeView>
</form>
</body>
</html>
ถามเกี่ยวกับ ASP.Net หน่อยครับ
<%@ Import Namespace="System.IO"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myDirInfo,myFolderInfo As DirectoryInfo
Dim arrFolderInfo As Array
myDirInfo = New DirectoryInfo(Server.MapPath("MyFiles/"))
arrFolderInfo = myDirInfo.GetDirectories
For Each myFolderInfo In arrFolderInfo
Me.lblText.Text = Me.lblText.Text & (myFolderInfo.Name & "<br>")
Next myFolderInfo
myDirInfo = Nothing
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - List Directory</title>
</head>
<body>
<form runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br />
</form>
</body>
</html>