文件读取.aspx.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 文件读取 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] arrs = Directory.GetFiles(MapPath("files"));//Directory
foreach (string _s in arrs)
{
Response.Write(_s + "<br/>");//读取完整物理路径
}
Response.Write("-----------------------------------------------------------------------" + "<br/>");
foreach (string _s in arrs)
{
string _fname = Path.GetFileName(_s);//path类下的GetFileName
Response.Write(_fname + "<br/>");//读取文件名
}
Response.Write("-----------------------------------------------------------------------" + "<br/>");
foreach (string _s in arrs)
{
string _fname1 = Path.GetFileNameWithoutExtension(_s);
Response.Write(_fname1 + "<br/>");//不带扩展名的文件名
}
}
}
效果如图: