C# – ASP.NET – Directory Explorer

<%@ Page Language=”C#” %>
<%@ Import Namespace = “System.IO” %>
<%Server.ScriptTimeout = 90;%>
<script runat=”server”>
    void listFolder(string folder) {
        Response.Write(“<h1>” + folder + “</h1>”);
        Response.Write(“<h3>Files</h3>”);
        string [] fis = Directory.GetFiles(folder);
        foreach(string fi in fis) {
            Response.Write(fi + “<br>”);
        }
        Response.Write(“<h3>Folders</h3>”);
        string [] fos = Directory.GetDirectories(folder);
        foreach(string fo in fos) {
            string a = “<a href=\”” + “?dir=” + fo + “\”>” + fo + “</a>”;
            Response.Write(a + “<br>”);
        }
    }
</script>
<html><body>
<%
    string folder = Request.QueryString[“dir”];
    if (folder == null) folder = Server.MapPath(“.”);
    listFolder(folder);
%>
</body></html>