我把文件存入数据库,数据类型是image,现在我读出数据,
如果我存入的是图片或.txt文件打开没什么问题,
我现在把一个word文档存入数据库中,打开的文件是空白的只有两行字,“word数据页头/word数据页尾“
这是什么原因,请高手们帮忙解决一下。

解决方案 »

  1.   

    SqlCommand Cmd=new SqlCommand(strSql,Conn);
    SqlDataReader dr =Cmd.ExecuteReader();
    if(dr.Read())
    {
    Response.Clear();
    if(dr["FileType"].ToString()=="application/msword")
    {
    Response.ContentType = "application/msword";//word格式
    }
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(dr["FileName"].ToString()));
    // Response.AddHeader("Content-Disposition", dr["FileName"].ToString());
    Response.Flush();
    Response.BinaryWrite((byte[])dr["FileBody"]);
    Response.End();
    }
    dr.Close();