//下载
        string filePath = Server.MapPath("../Temp/" + ofname);//路径
        FileInfo fileInfo = new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.UrlEncode(ofname) + "\"");//防止中文名出乱码,不过文件名中的空格会被“+”代替
        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();

posted on 2014-02-21 16:41  御不凡  阅读(284)  评论(0编辑  收藏  举报