vs.net中打开数据库中的文件(保存/下载)

来源:互联网 发布:武汉软件测试 编辑:程序博客网 时间:2024/05/22 13:41

  private void Download(Byte[] filedata, string sFileName)
        {
            HttpContext context = HttpContext.Current;
            if (context != null)
            {
                context.Response.Clear();
                context.Response.Charset = "utf-8";
                context.Response.Buffer = true;
                context.Response.ContentType = "application/msword";
                context.Response.ContentEncoding = System.Text.Encoding.UTF8;

                //下载
                //context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + sFileName); 
               

                context.Response.AppendHeader("Content-Disposition", "inline"); //直接打开
                context.Response.BinaryWrite(filedata);
                context.Response.Flush();
                context.Response.Close();
                context.Response.End();
            }
        }

其他格式文件,修改 context.Response.ContentType

 

 

 

原创粉丝点击