从数据库中将以image类型存入的word文件读出,在ie中用word显示,但是没有数据,只有一个word框架(难道一定要用一个filestream先将读出的内容放到一个文件中吗)public void LoadBinary()
{
SqlCommand cmd=new SqlCommand();
cmd.CommandText="select image from temp where ename='ReportDoc'";
cmd.Connection=conn;
conn.Open();
SqlDataReader binaryReader=cmd.ExecuteReader();

while(binaryReader.Read())
{
Response.ContentType="Application/msword";
Response.BinaryWrite((byte[])binaryReader["image"]);
}
binaryReader.Close();
conn.Close();
}请各位大虾帮忙看看

解决方案 »

  1.   

    public void LoadBinary()
    {
    SqlCommand cmd=new SqlCommand();
    cmd.CommandText="select image from temp where ename='ReportDoc'";
    cmd.Connection=conn;
    conn.Open();
    SqlDataReader binaryReader=cmd.ExecuteReader();

    binaryReader.Read()
    Dim Buffer() As Byte    
    Buffer=binaryReader("列名")
    conn.Close(); Response.ContentType = "Application/octet-stream";
            Response.Clear();
            Response.AddHeader("Content-Disposition", " filename=");
            Response.BinaryWrite(Buffer);
            Response.End();


    }
      

  2.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=13C874E4-7FC7-4FD1-8CF6-DE9EF4469A9C
      

  3.   

    byte[] btImage = (byte[])o;
    Response.ContentType = "Application/octet-stream";
    Response.Clear(); //文件名包括你的文件的后缀(.doc)
    Response.AddHeader("Content-Disposition", " filename= a.doc");
    Response.BinaryWrite(btImage);
    Response.End();
      

  4.   

    我希望的是在ie中用word的方式(也就是Response.ContentType="Application/msword")将读出的二进制流直接在ie中显示,这样可以吗?现在的问题是,在ie中的word框架下没有数据,(我试了一下,用text/html可以显示一些乱码,这说明可以读到二进制流,但是为什么用application/msword就显示不了数据)
      

  5.   

    public void LoadBinary()
    {
    SqlCommand cmd=new SqlCommand();
    cmd.CommandText="select image from temp where ename='HelpDoc'";
    cmd.Connection=conn;
    conn.Open();
    SqlDataReader binaryReader=cmd.ExecuteReader();
    binaryReader.Read();

     
    byte[] buffer=(byte[])binaryReader["image"];


    binaryReader.Close();
    conn.Close();
    Response.ContentType = "Application/octet-stream";
    Response.Clear();
    Response.AddHeader("Content-Disposition", "filename=ttt.doc");
    Response.BinaryWrite(buffer);
    Response.End();

    修改后的,执行了一遍,依然没有显示数据


    }
      

  6.   

    我希望的是在ie中用word的方式(也就是Response.ContentType="Application/msword")将读出的二进制流直接在ie中显示,这样可以吗?现在的问题是,在ie中的word框架下没有数据,(我试了一下,用text/html可以显示一些乱码,这说明可以读到二进制流,但是为什么用application/msword就显示不了数据)
    byte[] btImage = (byte[])o;
    Response.ContentType = "Application/octet-stream";
    Response.Clear(); //文件名包括你的文件的后缀(.doc)
    Response.AddHeader("Content-Disposition", " filename= a.doc");
    Response.BinaryWrite(btImage);
    Response.End();
    ***********************************所用的代码是没问题。你要解决的问题是:1:显示Word页面应为空白页面,即无任何控件。
    2:
    建议在客户机试运行看看效果? 
      

  7.   

    多谢各位!尤其是lutao206(海口冰玲)
    在客户端确实可以显示数据