Listing Folders in a Directory using asp.net and C#

// YourPage.aspx
<%@ Import Namespace="System.IO" %>
<html>
<body>
    <% foreach (var dir in new DirectoryInfo("E:\\TEMP").GetDirectories()) { %>
        Directory: <%= dir.Name %><br />

        <% foreach (var file in dir.GetFiles()) { %>
            <%= file.Name %><br />
        <% } %>
        <br />
    <% } %>
</body>
</html>

我服用中的版本:

 <ul>
 <%
 System.IO.DirectoryInfo diFiles = new System.IO.DirectoryInfo(Server.MapPath("/ImgUpload/"));
 foreach (var f in diFiles.GetFiles())
 {
 Response.Write("<li><img src='/ImgUpload/" + f.Name + "' width='200'/></li>");
 }
 %>
 </ul>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *