使用asp.net和C#列出目录中的文件夹
||
.aspx文件:
<%@ Import Namespace=\"System.IO\" %>
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head id=\"Head1\" runat=\"server\">
<title>Explorer</title>
</head>
<body>
<form id=\"form1\" runat=\"server\">
</form>
</body>
</html>
.CS文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class view2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string path = \"~/\";
GetFilesFromDirectory(path);
}
private static void GetFilesFromDirectory(string DirPath)
{
try
{
DirectoryInfo Dir = new DirectoryInfo(DirPath);
FileInfo[] FileList = Dir.GetFiles(\"*.*\", SearchOption.AllDirectories);
foreach (FileInfo FI in FileList)
{
Console.WriteLine(FI.FullName);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
我想在特定目录中列出文件夹,但该文件夹连续显示空白页。任何人都可以在代码中说出问题所在。
没有找到相关结果
已邀请:
5 个回复
需复
舶啥戚
来使用
。您正在尝试在Web应用程序中写入控制台。
填盖
悍蕾驮苇袜
疮痪徘弦漏
在aspx页面