http://expert.csdn.net/Expert/topic/1397/1397527.xml?temp=2.672976E-02

解决方案 »

  1.   

    this.Response.ClearHeaders();
    this.Response.Clear();
    this.Response.Buffer=false;
    System.Data.OleDb.OleDbConnection odc=new OleDbConnection();
    odc.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+this.Server.MapPath("MyDB\\") +
    System.Configuration.ConfigurationSettings.AppSettings["connstr"];
    OleDbDataReader dr;
    OleDbCommand odcd=new OleDbCommand("Select * From [Code] Where CodeID="+this.Request.QueryString["id"],odc);
    odc.Open();
    dr=odcd.ExecuteReader();


    if(!dr.Read())
    this.Response.Redirect(""); string filename=dr["filename"].ToString();
    byte[] by;
    by=(byte[])dr["file2"];// this.Response.Write(filename);
    odc.Close();



    this.Response.AddHeader("Content-Disposition","attachment;filename="+System.Web.HttpUtility.UrlEncode(filename));
    this.Response.AddHeader("Content-Length",by.Length.ToString());
    this.Response.ContentType="application/octet-stream";
    this.Response.BinaryWrite(by);
    this.Response.End();