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();

解决方案 »

  1.   

    http://www.codeproject.com/asp/downloader.asp
      

  2.   

    我现在知可以用webClient.DownloadFile(myStringWebResource,fileName); 
    我想问以前的不用C#,是怎么做的?
      

  3.   

    我可以用WebClient.DownloadFile(myStringWebResource,fileName);,但怎样做进度条,以前的是怎么做的,谁有例子吗?
      

  4.   

    http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm(英文)
    http://www.yesky.com/20020910/1629570.shtml(中文)
    http://expert.csdn.net/Expert/topic/1200/1200373.xml?temp=.8520014(可断点续传)
      

  5.   

    这是用asp做的:
    --------------------------------------------------
      Response.Clear
      Response.Buffer = true
      Response.ContentType = "application/octet-stream"
      Response.AddHeader "Content-Disposition","attachment;filename=<文件名>"
      Response.BinaryWrite ts.ReadAll//要下载的数据
      Response.Flush
      Response.End
    ----------------------------------------------------