http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=5481

解决方案 »

  1.   

    private void Button3_Click(object sender, System.EventArgs e)
    {
    int fileDataCol = 0; 
    SqlConnection sqlconnection=new SqlConnection (strcon);
    SqlCommand scom=new SqlCommand ();
    scom.CommandText="select CONTENT,FILENAME from DOCUMENT WHERE ID=1";
         scom.Connection=sqlconnection;
    scom.Connection.Open();
    SqlDataReader dr=scom.ExecuteReader();
    dr.Read();
    string filename=Server.UrlEncode(dr.GetString(1));
    Byte[] b = new Byte[(dr.GetBytes(fileDataCol, 0, null, 0, int.MaxValue))];
    dr.GetBytes(fileDataCol, 0, b, 0, b.Length);
    dr.Close();
    sqlconnection.Close ();
    Response.ContentType="Application/msword";
    Response.AddHeader("Content-Disposition","attachment; filename="+filename);
    this.Response.Clear();
    System.IO.Stream fs=this.Response.OutputStream;
    fs.Write(b,0,b.Length);
    fs.Close();
    this.Response.End();

    }
    //本方法实现从数据库中读取word文档的内容,即下载;