By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,454 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,454 IT Pros & Developers. It's quick & easy.

Listing files in a directory

P: n/a
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.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 14 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Mike P" wrote:
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.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 14 '08 #2

P: n/a
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

"Mike P" <mi*******@gmail.comwrote in message
news:ua****************@TK2MSFTNGP02.phx.gbl...
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.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 14 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.