上传服务器的数字名称的附件下载时还原原来的名称

首先定义一个新的页面a.aspx,来获得附件的实际名称和原来的名称

获得的附件信息为:“20131201020222.doc|通知.doc”,然后调用下面的方法,即可实现。

<a href='../a.aspx?fileServerName=" + s[1] + "&fileName=" + s[0] + "'>" + s[0] + "</a> <br/>"

 

 

  ///<summary>
   
/// Response.AddHeader实现下载
   
///</summary>
   
///<param name="filePath">完整的文件路径</param>
   
///<param name="fileName">文件名</param>
    privatevoid DownFile(string filePath, string fileName)
    {
        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("utf-8");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();
    }
posted @ 2013-03-21 15:47  川聚常  阅读(219)  评论(0编辑  收藏  举报