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;
}
}
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