you cannot do that on the server side in C#, you have to do it on the client side using scripting. Also, you need to enable ActiveX security settings on the client side machine, then try something like<script language="javascript">
var fso = new ActiveXObject("Scripting.FileSystemObject");function ShowFile(folder)
{
var fc, s="";
fc = new Enumerator(folder.files);
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
function ShowFolderContent(folder)
{
var fc, s;
s = ShowFile(folder);
fc = new Enumerator(folder.SubFolders);
for (;!fc.atEnd(); fc.moveNext())
{
s += ShowFolderContent(fc.item());
s += "<br>";
}
return(s);
}document.write(ShowFolderContent(fso.GetFolder("e:\\labs\\html")));
</script>
var fso = new ActiveXObject("Scripting.FileSystemObject");function ShowFile(folder)
{
var fc, s="";
fc = new Enumerator(folder.files);
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
function ShowFolderContent(folder)
{
var fc, s;
s = ShowFile(folder);
fc = new Enumerator(folder.SubFolders);
for (;!fc.atEnd(); fc.moveNext())
{
s += ShowFolderContent(fc.item());
s += "<br>";
}
return(s);
}document.write(ShowFolderContent(fso.GetFolder("e:\\labs\\html")));
</script>
this.LblFilePath.Text=getpath;
ProcessDirectory(ListData,getpath) ;
public static void ProcessDirectory(ListBox ListData,string targetDirectory)
{
//Remove All ListBox Item Frist
// Recurse into subdirectories of this directory
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
//ProcessDirectory(subdirectory);
ListData.Items.Add(subdirectory.Replace(targetDirectory+"\\","")+" <目录>");
// Process the list of files found in the directory
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ListData.Items.Add(fileName.Replace(targetDirectory+"\\",""));
}
{
lstEmployee.Items.Clear() ; lstEmployee.DataSource = dsEmployee.Tables[0].DefaultView;
lstEmployee.DataTextField = "FullName";
lstEmployee.DataValueField ="EmployeeID";
lstEmployee.DataBind();
}
lstEmployee为一个listbox名
dsEmployee为一个DataSet
DataTextField填写显示的字段名
DataValueField填写隐藏字段名取值时lstEmployee.SelectedItem.Text (显示的)
lstEmployee.SelectedItem.Value(隐藏)