当前位置: 代码迷 >> ASP.NET >> 网页显示文件名点击上载
  详细解决方案

网页显示文件名点击上载

热度:605   发布时间:2013-02-25 00:00:00.0
网页显示文件名点击下载
网页上显示指定文件夹中的文件并且点击实现下载。

------解决方案--------------------------------------------------------
HTML code
<a href="文件的具体地址">点击下载</a>
------解决方案--------------------------------------------------------
只能打包下载,B/S好多人都在问能不能批量下载;至今都没好的解决方案。
------解决方案--------------------------------------------------------
C# code
 nP += "<a href=指定下载页面.aspx?path="+finfo[i].FullName+">"+finfo[i].Name+"</a>"+"<br>";然后在下载页面的 pageload中写代码如下        string filePath =Request["path"];//通过URL传过来的参数        FileInfo fileInfo = new FileInfo(filePath);        Response.Clear();        Response.ClearContent();        Response.ClearHeaders();        Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);        Response.AddHeader("Content-Length", fileInfo.Length.ToString());        Response.AddHeader("Content-Transfer-Encoding", "binary");        Response.ContentType = "application/octet-stream";        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");        Response.WriteFile(fileInfo.FullName);        Response.Flush();        Response.End();
  相关解决方案