Reputation: 689
I have a drop down list on my page & want the list items to be folders from a local directory on the web server... ie....
T:\Forms T:\Manuals T:\Software
Here is my code so far...
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/");
DirectoryInfo[] dirArray = di.GetDirectories();
DropDownList1.DataSource = dirArray;
foreach (DirectoryInfo i in dirArray)
{
DropDownList1.DataTextField = i.FullName;
DropDownList1.DataValueField = i.FullName;
}
}
SOLVED
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/");
DropDownList1.DataSource = di.GetDirectories();
DropDownList1.DataBind();
foreach (DirectoryInfo i in di.GetDirectories())
{
DropDownList1.DataTextField = i.FullName;
}
}
Upvotes: 0
Views: 2605
Reputation: 8359
I would suggest using such a piece of code
DirectoryInfo di = new DirectoryInfo(@"e:\");
ddlFolders.DataSource = di.GetDirectories();
ddlFolders.DataTextField = "Name";
ddlFolders.DataValueField = "FullName";
ddlFolders.DataBind();
hth
Upvotes: 3
Reputation: 2914
You can use
List<string> dirList=new List<string>();
DirectoryInfo[] DI = new DirectoryInfo(@"T:\Forms\").GetDirectories("*.*",SearchOption.AllDirectories ) ;
foreach (DirectoryInfo D1 in DI)
{
dirList.Add(D1.FullName);
}
Do that for all three directories and then databind to the list
Upvotes: 1
Reputation: 18013
Check out the
System.IO.DirectoryInfo
and
System.IO.FileInfo
classes. Obviously you will only be able to read the filesystem of the web server
Upvotes: 1