Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,468 times

Related Categories

How to get an array of all files in a directory

This simple code will give you an array containing all files in a directory.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
    void Page_Load(object sender, EventArgs e) {
        FileInfo fi = new FileInfo(Server.MapPath(""));
        DirectoryInfo di = fi.Directory;
        FileSystemInfo[] fsi = di.GetFiles();
        Response.Write("The directory contains the following files and directories:" + di.FullName + "<hr>");
        foreach (FileSystemInfo info in fsi)
            Response.Write(info.Name + "<br>");
    }
</script>

Edward Tanguay updates his personal web site tanguay.info weekly with code, links, quotes and thoughts on web development. Sign up for the free newsletter.

Comments