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)
{
DropDownLis开发者_如何学Pythont1.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;
}
}
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
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
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
精彩评论