为什么我一点ListDrives.aspx页面里面的驱动盘符就会出错:显示编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1501: 重载“Directory”方法未获取“1”参数源错误: 行 12:   try
行 13:   {
行 14:     thisOne = new Directory(strDirToList);   就是这行有错误
行 15:  //读取目录内的文件夹
行 16:  Response.Write("<p>Creation:" + thisOne.CreationTime.ToString() + "<p>");
 
帮帮忙吧ListDrives.aspx页面<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.IO" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<script language="c#" runat="server">
public void Page_Load(Object src,EventArgs e)
{
  string[] achDrives = Directory.GetLogicalDrives();
  int nNumOfDrives = achDrives.Length;
  Response.Write("<ul>");
  for(int i=0;i<nNumOfDrives;i++)
  {
    Response.Write("<li><a href=\"listdir.aspx?dir=");
Response.Write(Server.UrlEncode(achDrives[i]));
Response.Write("\">"+achDrives[i]);
Response.Write("</a><br>");
  }
  Response.Write("</ul>");
}
</script>
<body></body>
</html>listdir.aspx页面
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.IO" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<%
  string strDirToList = Request.QueryString["dir"];
  Directory thisOne = null;
  try
  {
    thisOne = new Directory(strDirToList);
//读取目录内的文件夹
Response.Write("<p>Creation:" + thisOne.CreationTime.ToString() + "<p>");
Directory[] subDirectories = thisOne.GetDirectories();
Response.Write("<ul>");
for(int i=0;i<subDirectories.Length;i++)
{
  Response.Write("<li><a href=\"listdir.aspx?dir=");
  Response.Write(Server.UrlEncode(subDirectories[i].FullName));
  Response.Write("\">"+subDirectories[i].Name);
  Response.Write("</a><br>");
}
Response.Write("</ul>");
//读取目录内的文件
File[] theFiles = thisOne.GetFiles();
Response.Write("<ul>");
for(int i=0;i<theFiles.Length;i++)
{
  Response.Write("<li><a href=\"showfile.aspx?file=");
  Response.Write(Server.UrlEncode(theFiles[i].FullName));
  Response.Write("\">"+theFiles[i].Name);
  Response.Write("</a><br>");
}
Response.Write("</ul>");
  }
  catch(Exception ee)
  {
    Response.Write("Access not Possible!<i>");
Response.Write(ee.ToString()+"</i>");
Response.End();
  }
%>
<body></body>
</html>

解决方案 »

  1.   

    把你的Directory替换成DirectoryInfo
    还有下面的File替换成FileInfo
      

  2.   

    行了,可以浏览了是不是这个不支持中文目录名,英文目录名都能打开,碰到中文命名的就出现异常错误了
    Creation:1601-1-1 8:00:00Access not Possible!System.IO.DirectoryNotFoundException: 未找到路径“E:\E_??”的一部分。 at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.Directory.InternalGetFileDirectoryNames(String fullPath, String userPath, Boolean file) at System.IO.DirectoryInfo.GetDirectories(String searchPattern) at System.IO.DirectoryInfo.GetDirectories() at ASP.listdir_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer)
      

  3.   

    使用Server.UrlEncode()编码 就可以了