I want to get folder Name from directory...and add the folder name to drop down list...
can anyone tell the code...
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Riyaz AkhtarRank #2,275 · 619 reputationPosted Jun 17, 2013, 12:43 AM EDT
Riyaz AkhtarRank #2,275 · 619 reputationPosted Jun 17, 2013, 12:48 AM EDT
selva kumarRank #2,987 · 483 reputationPosted Jun 17, 2013, 12:48 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 17, 2013, 12:58 AM EDT
hi,
yes with the help of GetDirectories method of DirectoryInfo object you can get list of all folder with in given folder.
var k = new System.IO.DirectoryInfo(@"D:\test");
foreach (var p in k.GetDirectories())
{
Console.WriteLine(p.FullName);
}
Please refer
http://www.developerfusion.com/code/4359/listing-files-folders-in-a-directory/
hope this will help you.
Hoang An16 reputationPosted Jun 17, 2013, 1:12 AM EDT
Example:
string strDirPath="D:\\Dir";
DirectoryInfor dinfor=new DirectoryInfor(strDirPath);
foreach(DirectoryInfor d in dinfor.GetDirectories())
{
listbox.item.add(d.FullName);
}
selva kumarRank #2,987 · 483 reputationPosted Jun 17, 2013, 1:13 AM EDT
selva kumarRank #2,987 · 483 reputationPosted Jun 17, 2013, 1:20 AM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 17, 2013, 2:54 AM EDT
using System.IO;
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 17, 2013, 10:24 AM EDT
using system.IO;
then write this code for bind folder names from a directory
string strDirPath = @"D:\";//path of the drive or folder
DirectoryInfo dinfor = new DirectoryInfo(strDirPath);
foreach (DirectoryInfo d in dinfor.GetDirectories())
{
DropDownList1.Items.Add(d.FullName.Replace(@"D:\", ""));
}
if you want to bind files from a folder then write following code
DirectoryInfo dir = new DirectoryInfo(MapPath("Zip"));//Folder path
FileInfo[] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach (FileInfo info in files)
{
listItems.Add(info);
}
DropDownList1.DataSource = listItems;
DropDownList1.DataBind();
any problem rply