对你的代码进行了测试,我这边没有错误.aspx  File  Code:
<%@ Page language="c#" Codebehind="TryForm.aspx.cs" AutoEventWireup="false" Inherits="EverythingTry.PrintMethod.TryForm" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>TryForm</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<!--  加入背景音乐
<bgsound src="PLEASE FORGIVE ME.mp3" loop="infinite" balance="0" volume="0">
-->
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 40px" runat="server"
Text="download" Width="72px"></asp:Button></FONT>
</form>
</body>
</HTML>

解决方案 »

  1.   

    .aspx.cs  Code:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO;namespace EverythingTry.PrintMethod
    {
    /// <summary>
    /// TryForm 的摘要说明。
    /// </summary>
    public class TryForm : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string FilePath=Server.MapPath("/EverythingTry")+@"..\AutoCAD\Drawing_1.dwg";
    System.IO.FileStream iStream=new FileStream(FilePath,FileMode.Open,FileAccess.Read,FileShare.Read); long FileLength=iStream.Length; long ByteToRead=FileLength; FileInfo fileinfo = new FileInfo(FilePath); String FileName = fileinfo.Name; Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename="+HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", ByteToRead.ToString()); Response.Flush(); byte[] Buffer; int BufferLength=1000000; int Len=1; bool ClientClosed=false; while (Len>0 && ClientClosed==false)
    {
    Buffer= new Byte[BufferLength];
    Len = iStream.Read(Buffer, 0, BufferLength);
    Response.OutputStream.Write(Buffer,0,Len);
    Response.Flush();
    ClientClosed=!this.Response.IsClientConnected;
    } iStream.Close(); iStream = null;
    System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    }
    }
      

  2.   

    您好,非常感谢您的回复。 能告诉我您的qq或者msn么,这样探讨比较方便. 您可以发送到我的留言中我正常保存也没有问题。就是发生在:下载后我选择保存,然后再选择保存目录和文件名的时候我点击取消,然后我再次点击下载的时候屏幕马上乱码。好像感觉东西已经下下来了并且放在了html中。。因为用不同的文件测试显示不同的乱码。。
      

  3.   

    我测试过了。的确是把下载的文件放在了html中。 我怎么解决呢?
      

  4.   

    严重奇怪的是,我下载的是一个txt文件。 下完后,里面居然多出了:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>人力资源</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body onload="window.document.forms[0].txt_creater.focus()" MS_POSITIONING="GridLayout">
    <form name="Form1" method="post" action="RecruitSearch.aspx" id="Form1">
    <input type="hidden" name="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" value="dDwtMTQzNjI4NTA1NTt0PHA8bDxzdHJzcWw7PjtsPHNlbGVjdC这是怎么回事啊,把我的html的一部分也自动加进去了。是不是我设置上面的问题呢?
      

  5.   

    我使用 this.Response.End(); 终止线程。下载后的文件里面不再有哪些东西了。 但是再次点击的时候,出现错误:线程正被终止。 这时候我还没有运行下载线程阿,是不是上一个线程没有被关闭呢?
      

  6.   

    如果在浏览器中打开时,你看看你浏览器当前的编码,看看是不是这个问题,如果还不行
    试试将web.config中的:
            <globalization  requestEncoding="utf-8"  responseEncoding="utf-8" />
    改成
       <globalization  requestEncoding="gb2312"  responseEncoding="gb2312" />