List Files in a Directory in C#





7
Date Submitted Sat. Oct. 15th, 2005 5:42 PM
Revision 1 of 1
Helper ses5909
Tags CSharp | Directory | Files | List
Comments 0 comments
List Files in a Directory in C#
// you can get an array of files (their path) by using:
fileArray = Directory.GetFiles(yourPath);

//you can display all of the images in a directory by using:
ArrayList pics = new ArrayList();
string myFile;
string code;
const string YOUR_DIRECTORY = "/images/";
foreach (myFile in Directory.GetFiles(Server.MapPath(YOUR_DIRECTORY), "*.gif"))
{
    image = YOUR_DIRECTORY + Path.GetFileName(myFile);
    code = <"img src=\"" + image + "\">";
    pics.Add(code)// add the image to your ArrayList
}
// Bind the pics to a DataList
dlImages.DataSource = pics;
dlImages.DataBind;

Sara Smith

www.ilovecode.com
Sara

ilovecode

Comments

There are currently no comments for this snippet.

Voting