伙计们,在尝试实现一个类来枚举文件系统树的方式后,我放弃了尝试使其工作。
我有一个带有文件路径的文本框。我希望用户能够单击并从显示文件系统树的面板中单击并选择路径。
你们能帮我解决这个问题吗?
只是为了让您了解我在做什么,这是代码:
try
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
Response.Write("<ul class=\"jqueryFileTree\" style=\"display: none;\">\n");
foreach (DriveInfo drive in allDrives)
{
if (drive.IsReady == true)
{
try
{
Response.Write("\t<li class=\"drive collapsed\"><a href=\"#\" rel=\"" + drive.ToString() + "\">" + drive.ToString() + "</a>\n");
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(drive.ToString());
DirectoryInfo[] directories = di.GetDirectories("*.*", SearchOption.AllDirectories);
Response.Write("<ul>");
foreach (System.IO.DirectoryInfo di_child in directories)
{
Response.Write("\t<li class=\"directory collapsed\"><a href=\"#\" rel=\"" + drive + di_child.Name + "/\">" + di_child.Name + "</a>\n");
Response.Write("<ul>");
foreach (System.IO.FileInfo fi in di.GetFiles())
{
string ext = "";
if (fi.Extension.Length > 1)
{
ext = fi.Extension.Substring(1).ToLower();
}
Response.Write("\t<li class=\"file ext_" + ext + "\"><a href=\"#\" rel=\"" + drive + fi.Name + "\">" + fi.Name + "</a></li>\n");
}
Response.Write("</ul></li>");
}
Response.Write("</ul></li>");
}
catch (UnauthorizedAccessException e)
{
Response.Write(e.Message);
continue;
}
catch (System.IO.DirectoryNotFoundException e)
{
Response.Write(e.Message);
continue;
}
catch (Exception e)
{
Response.Write(e.Message);
continue;
}
}
}
Response.Write("</ul>");
}
catch (Exception)
{
throw;
}