直接让数据流下载,而不是显示在页面上.当然也不能在硬盘上创建这个文件,这该咋办呢?

解决方案 »

  1.   

    把传输方式改一下 不是 html/txt 改为 file/tream
      

  2.   

    类似于
    Response.BinaryWrite(encoding.GetBytes(yourStr));
                Response.Charset = "GB2312";
    Response.End();
    Response.Close();
      

  3.   

    System.IO.FileInfo file=new System.IO.FileInfo(文件路径);
             Response.Clear();
             Response.AddHeader("Content-Disposition","attachment;filename="+file.Name);
             Response.AddHeader("Content-Length",file.Length.ToString());
             Response.ContentType="application/octet-stream";
             Response.WriteFile(文件路径);
             Response.End();
      

  4.   

    TO: listhome(我听见猪来自地铁和人海) 
    我是从数据库直接读流,没有"文件路径"啊!
      

  5.   

    byte[] t;//这是从数据库读出来的文件放到一个 byte数组
    Response.ContentType="application/x-www-form-urlencoded";
    Response.AppendHeader("Content-disposition","attachment; filename="+HttpUtility.UrlEncode(filename));
    Response.BinaryWrite(t);
    Response.End();
      

  6.   

    我是这么写的:
    Response.Clear();
    //文件类型
    Response.ContentType = a.ContentType;
    //文件的二进制数据
    Response.BinaryWrite(a.ContentBytes);
    Response.End();
    Response.Close();
    图片直接会在页面上显示,ZIP等文件的话,会弹出下载对话框,但文件类型却是ASPX!!
    怎么让它弹出正确的文件类型下载??
      

  7.   

    谢谢: tavor(龙双公子) !!
    问题解决了.