主题:ASP.NET中获取驱动器及列出目录文件的问题?急!!
listdrives.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO"%>
<%
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>");
%>
listdir.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO"%>
<%
string strDir2list=Request.QueryString.Get("dir");
Directory thisOne=null;
try
{
thisOne=new Directory(strDir2list);
//Reading the directory properties
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.Lenth;I++)
{
Response.Write("<li><a href=\"showfile.aspx?file=");
Response.Write(Seerver.UrlEncode(thefiles[i].FullName));
Response.Write("\">"+thefiles[i].Name);
Response.Write("</a><br>");
}
Response.Write("</ul>");
}
catch (Excepton e)
{
Response.Write("Access not possible, error:<i>");
Response.Write(e.ToString()+"</i>");
Response.End();
}
%>
在执行时,可以列出驱动器,但是列出目录就有问题了。
提示listdir.aspx中
try
行 7: {
行 8: thisOne=new Directory(strDir2list); 此行重载“Directory”方法未获取 “1”参数
行 9: Response.Write("<p>Creation:"+thisOne.CreationTime.ToString()+"</p>");
请问那位朋友帮下忙指教一下,我也是刚开始学,希望大家多多帮忙啦!谢谢
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO"%>
<%
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>");
%>
listdir.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO"%>
<%
string strDir2list=Request.QueryString.Get("dir");
Directory thisOne=null;
try
{
thisOne=new Directory(strDir2list);
//Reading the directory properties
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.Lenth;I++)
{
Response.Write("<li><a href=\"showfile.aspx?file=");
Response.Write(Seerver.UrlEncode(thefiles[i].FullName));
Response.Write("\">"+thefiles[i].Name);
Response.Write("</a><br>");
}
Response.Write("</ul>");
}
catch (Excepton e)
{
Response.Write("Access not possible, error:<i>");
Response.Write(e.ToString()+"</i>");
Response.End();
}
%>
在执行时,可以列出驱动器,但是列出目录就有问题了。
提示listdir.aspx中
try
行 7: {
行 8: thisOne=new Directory(strDir2list); 此行重载“Directory”方法未获取 “1”参数
行 9: Response.Write("<p>Creation:"+thisOne.CreationTime.ToString()+"</p>");
请问那位朋友帮下忙指教一下,我也是刚开始学,希望大家多多帮忙啦!谢谢