//下载附件
    private void DownFile(string path) {

        path = "../UploadFile/19966845200812081005271.doc";
        path = Server.MapPath(path);
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        //清除缓冲区流中的所有内容输出

        Response.Clear();

        //将下载保存对话框指定默认的文件名添加到HTTP头中
        //Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

        Response.AddHeader("Content-Disposition", "attachment;   filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));//避免中文出现乱码现象  

        //在header中指定文件的大小,使浏览器能显示下载过程
        Response.AddHeader("Content-Length", file.Length.ToString());

        //设置输出流的 HTTP MIME 类型
        Response.ContentType = "application/octet-stream";

        // 发送文件流到客户端
        Response.WriteFile(file.FullName);
        // 停止该页的执行

        Response.End();
   
    }

posted on 2008-12-10 09:39  poop  阅读(262)  评论(1编辑  收藏  举报