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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Jun 17, 2013, 2:24 PM
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
Pankaj PandeyPosted Jun 17, 2013, 6:54 AM
using System.IO;
selva kumarPosted Jun 17, 2013, 5:20 AM
selva kumarPosted Jun 17, 2013, 5:13 AM
Hoang AnPosted Jun 17, 2013, 5:12 AM
Example:
string strDirPath="D:\\Dir";
DirectoryInfor dinfor=new DirectoryInfor(strDirPath);
foreach(DirectoryInfor d in dinfor.GetDirectories())
{
listbox.item.add(d.FullName);
}
Jignesh TrivediPosted Jun 17, 2013, 4:58 AM
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.
selva kumarPosted Jun 17, 2013, 4:48 AM
Riyaz AkhtarPosted Jun 17, 2013, 4:48 AM
Riyaz AkhtarPosted Jun 17, 2013, 4:43 AM