I want to list all files and subdirectories available in particular directory? Is it possible to do it using asp.net? I am usign c# with the asp.net.
THank you
I want to list all files and subdirectories available in particular directory? Is it possible to do it using asp.net? I am usign c# with the asp.net.
THank you
You can use directoryinfo and fileinfo class of System.io namespace
Following code will display files in listbox
PHP Code:DirectoryInfo dirCustom = new DirectoryInfo(txtPath.Text);
FileInfo[] filCustom;
filCustom = dirCustom.GetFiles("*.*");
foreach (FileInfo filFile in filCustom)
{
listbox1.items.add(filfile.name);
}
i think its not bossible to list all the files and sub directories in the particular directory in asp.net
it is possible through the listbox control.then place the listbox control then goto edit items property.then click add items
well i don't know the answer of that..
and techkid have given you the answer..
i think that's the only way to do that...
still i have not tried it but its just a suggestion...
Try out this code.
public void GetFiles(string path)
{
if (File.Exists(path))
{
// This path is a file
ProcessFile(path);
}
else if (Directory.Exists(path))
{
// This path is a directory
ProcessDirectory(path);
}
}
// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Insert logic for processing found files here.
public void ProcessFile(string path)
{
FileInfo fi = new FileInfo(path);
Response.Write("File Number " + position.ToString() + ". Path: " + path + " <br />");
position++;
}
Bookmarks