服务器文件流下载

来源:互联网 发布:unity开发2d麻将源码 编辑:程序博客网 时间:2024/04/28 14:29

System.IO.FileStream fs = new System.IO.FileStream(“文件路径”, System.IO.FileMode.Open, System.IO.FileAccess.Read);

        byte[] bFile = new byte[fs.Length];

        System.IO.BinaryReader r = new System.IO.BinaryReader(fs);

        bFile = r.ReadBytes((int)fs.Length);

        r.Close();

        r = null;

        fs.Close();

        Response.Clear();

        Response.Buffer = true;

        Response.Charset = "GB2312";

        Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(“导出文件名称.xls”)); // attachment 改为 online 则在线打开

                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//utf-8

        Response.ContentType = "application/ms-excel";

        Page.EnableViewState = false;

        Response.BinaryWrite(bFile);

        Response.Flush();

        Response.End();

 
原创粉丝点击