这个问题我在写Java的时候也遇到过!

解决方案 »

  1.   

    首先:页面AutoEventWireup设置为false其次:
    Response.Clear();
    this.Response.AppendHeader("Content-Disposition","attachment;filename="+文件名称);
    this.Response.Charset ="UTF-8";
    this.Response.ContentEncoding =System.Text.Encoding.Default;
    this.Response.WriteFile(this.Attachments.AbsolutePath(this.DropDownListAttachments.SelectedItem.Text.Trim()));
    this.Response.End();
      

  2.   

    你用下面的方法试一下
    1. if you are using code behind, make AutoEventWireup=false in your aspx page2. make sure you don't have ButtonViewAttachment_Click hooked up in two places, i.e., once in the aspx, once in InitComponents3. also, call Response.Clear() private void ButtonViewAttachment_Click(object sender, System.EventArgs e)
    {
     if(null==this.DropDownListAttachments.SelectedItem)
      return;         Response.Clear();
     this.Response.AppendHeader("Content-Disposition","attachment;filename="+this.DropDownListAttachments.SelectedItem.Text.Trim());
     this.Response.Charset ="UTF-8";
     this.Response.ContentEncoding =System.Text.Encoding.Default;
     this.Response.WriteFile(this.Attachments.AbsolutePath(this.DropDownListAttachments.SelectedItem.Text.Trim()));
     this.Response.End();
    }4. by the way, it is a bad idea to output the file in the same aspx, consider to use a separate page instead
      

  3.   

    可以这样做,
    下载的程序放在另外单独的页面的page_load里。 如download.aspx本页加一个iframe 每次下载的时候,传个id 号过去就可以了设iframe.src = download.aspx?id = idnumber 
      

  4.   

    我用 pgj(盼盼蛋奶茶) 的方式:AutoEventWireup设置为false了,代码是
    Response.ClearContent();
    Response.Clear();
    //文件流输出
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + strDisplayname);
    Response.ContentType = "application/octet-stream";
    this.Response.Charset  =  "UTF-8";
    this.Response.ContentEncoding  =System.Text.Encoding.Default;  
    Response.BinaryWrite(DocBuffer);
    //结束文件流输出
    Response.End();还是要弹出两次.是不是我分帧的缘故?而且在弹出第一个窗口的时候,后面没有下载窗口(也就是下载对话框:有估计剩余时间,下载到..等等的信息的窗口),点击打开又弹出一样的窗口后面有个下载窗口.但是点击保存的话,窗口就不会再弹出来了.我在后台跟踪的时候,代码是运行一遍的,而且到了Response.End();的时候就抛出异常({"线程正被中止。" })
      

  5.   

    新建一个页面,在page_load事件中写:try
    {
    if(!Page.IsPostBack)
    {
    string strFileName ="";
    strFileName = Request.QueryString["FILE_NAME"].ToString();
    strFileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(strFileName));
    Response.Clear();
    Response.ContentType = "application/x-msexcel";
    Response.AddHeader("Content-Disposition", "inline; filename="+strFileName);
    System.IO.FileStream MyFileStream =new FileStream(Request.QueryString["REPORT_FILE"].ToString(),System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
    long FileSize = MyFileStream.Length;
    byte[] Buffer = new byte[(int)FileSize];
    MyFileStream.Read(Buffer, 0, (int)FileSize);
    MyFileStream.Close();
    Response.BinaryWrite(Buffer);
    }
    }
    catch(Exception exp)
    {
    Response.Write("导出数据错误!");
    }
    在前面一个页面完成数据填入工作并调用上面页面:string  Buffer = this.theucExportExcelLogic.SetDataToExcel(this._ExportData, this._ExportHeaderData, strFileName,this._HeaderType, this._OnlyVisible);
    Response.Clear();
    Response.Redirect("../../ExportExcel/ShowReport.aspx?REPORT_FILE=" + Buffer+"&FIlE_NAME="+this._OutFileName ,true);
      

  6.   

    全面搞定!哈哈~~开心死了!!!页面aa.htm
    aaaa页面bb.htm
    bbbb页面kk.htm
    <HTML><body>
    <iFrame id="iframe" with=100px height=100px src="aa.htm"></iFrame>
    <script language="javascript">iframe.document.location.href="bb.htm"</script>
    </body></HTML>运行会看到 bbbb.
      

  7.   

    .aspx
    <iframe name="iframe" width="1" height="1" src='Download.aspx' frameborder="0" runat="server" ID="Iframe1">.aspx.cs
    if(!this.Page.IsStartupScriptRegistered("dgscript"))
    {
        Page.RegisterStartupScript("dgscript","<script Language=\"Javascript\">iframe.document.location.href='Download.aspx?id=" + id + "';</script>");
    }
      

  8.   

    Download.aspx.cs的page_load自动加载if(this.Request.Params["id"] != null)
    {
      //..........
    }