Listing files in a directory

M

Mike P

Is it possible to write some code to print to the screen a listing of
all files within a directory? I want to show the path of each file on
screen and enable the user to download any of the files.
 
C

Ciaran O''Donnell

So is this for a web application.
To get whats in a directory Directory.GetFiles() will return a string array
of file names.
If this is for a webapplication then you will need to make sure the folder
is web accessible before you can give out a link to it.
 
L

Leo Seccia

Hello,

Try:

DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/filefolder");
FileInfo[] rgFiles = di.GetFiles("*.*");
foreach(FileInfo fi in rgFiles)
{
Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");
}


Leo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top