List Files in a Directory in C#
7
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;
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;






There are currently no comments for this snippet.