日期:2014-05-18  浏览次数:20407 次

如何实现:列出下载文件夹中的文件名,并使列出的文件名具有超链属性,点击可以下载?
想实现文件上传和下载功能,能在指定的地方(如 <table> </table> )中列出上载文件中的文件名,点击可下载?

------解决方案--------------------
你应该有一个download.aspx用于下载。

<%@ Page Language= "C# " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<script runat= "server ">

protected void Page_Init(object sender, EventArgs e)
{
this.Response.ContentType = "application/octet-stream ";
this.Response.AddHeader( "Content-Disposition ", "attachment ");
string fn = Server.MapPath( "~/app_data/downloads/ " + this.Request.QueryString[ "url "]);
Response.TransmitFile(fn);
Response.End();
}
</script>

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
</form>
</body>
</html>


或者你google关键字“asp.net writefile”、“asp.net transmitfile”可以找到许许多多下载文件的示例。

文件不应该放在随便一个客户都可以下载的地方,而应该使用download.aspx这个程序在运行时下载。这个下载程序进行优化,可以支持断点序传、用户权限判断、根据用户参数使用同样的名称下载不同的内容等等。