zoukankan      html  css  js  c++  java
  • 从Oracle的Blob字段中下载文件

    思路:从Blob字段中获取byte数组,然后将byte数组输出到客户端,注意设置网页的Header

    代码如下:

     1 string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
     2 string sqlstr = "select file_name,FILECONTENT from fjg_file_manage where numbers='" + FileNum + "'";
     3 OracleConnection conn = new OracleConnection(constr);
     4 OracleCommand cmd = new OracleCommand(sqlstr, conn);
     5 
     6 conn.Open();
     7 OracleDataReader dr = cmd.ExecuteReader();
     8 dr.Read();
     9 //由于文件名中有空格,下载后空格会变成加号(+),因此需要进行特殊处理
    10 string fileName = HttpUtility.UrlEncode(fileName,Encoding.UTF8);   //编码后空格会变成加号
    11 fileName = fileName.Replace("+", "%20"); //将加号替换为空格
    12 //一定要设置好header,不然网页中不会弹出下载框
    13 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
    14 HttpContext.Current.Response.ContentType = "application/octet-stream";
    15 context.Response.BinaryWrite((byte[])dr["FILECONTENT"]);
    16 conn.Close();
  • 相关阅读:
    数据库默认隔离级别
    openldap安装
    new word
    ldap概念
    Oracle 计算函数
    informix 学习资料收集
    convert to groovy project
    ldap资料
    hibernate session
    IE BUG相关文章集合
  • 原文地址:https://www.cnblogs.com/neverstop/p/2759335.html
Copyright © 2011-2022 走看看