try something like this:Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name);
Response.ContentType = "application/octet-stream";Response.WriteFile(file.FullName);

解决方案 »

  1.   

    请问 "application/octet-stream";是这什么意思,当我用中文作为文件名时,为什么会出去乱码?是不是与 "application/octet-stream";有关?这个问题解次就结帖。
      

  2.   

    application/octet-stream//这里指的是8位字节的流
    MIME是internet上的多媒体扩展形式思归的方法是通过该形式
    输出.由于是流我想应该不具备编码格式所以你在接收的时候
    要有一个专门的转化
      

  3.   

    但是我这样也不行:Response.ContentType ="Text/HTML";
    那应该怎样设置才不会出现乱码?
    代码如下:
    string strSQL ;
    OleDbCommand Cmd = new OleDbCommand() ;
    OleDbDataReader Rearder ;
    Conn.Open ();
    strSQL = "select ht_Content from tempTable where id =" + id;
    Cmd.CommandText = strSQL ;
    Cmd.Connection = Conn ;

    Rearder = Cmd.ExecuteReader() ;
    Rearder.Read();

                    
    Response.AddHeader("Content-Disposition", "attachment; filename="内容.html" );

    Response.ContentType = "application/octet-stream";
    Response.Output.Write(Rearder["ht_Content"]);
      Conn.Close ();
    Response.End();以下代码可以把数据库text类型字段内容保存成文件名为“内容.html",不过文件名"内容"两字变成了乱码了。
      

  4.   

    tryResponse.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("内容.html") );