using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Web;
protected void Page_Load(object sender, EventArgs e)
{
display_files("/j1", "*.asp"); //"all" 代表全部类型的文件
}
public void display_files(string path,string type)
{
string fpath = Server.MapPath(path);
pttt.Text = fpath;
if (type == "all")
{
type = "*.*";
}
string[] files = Directory.GetFiles(fpath,type, SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
string fname = Path.GetFileNameWithoutExtension(file);
//list1.Items.Add(file);
// string http = Request.ServerVariables("server_name");
Response.Write ("<a target='_blank' href=http://localhost/"+path+'/'+Path.GetFileName(file)+">"+Path.GetFileName(file)+"</a><br>");
}
}
效果:
