HttpContext.Current.Response.ClearContent();
           HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="+filename );
            HttpContext.Current.Response.AddHeader("Content-Length", bt.Length.ToString());            HttpContext.Current.Response.ContentType = conttype;
            HttpContext.Current.Response.BinaryWrite(bt);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
上面是一个文件输出的代码
我想实现,如果文件是JPG的就直接在IE里打开了,如果是PDF客户端装有那东西也在IE里找开
如果是EXE之类的文件就直接下载了
可是如果注掉以下代码
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="+filename );
HttpContext.Current.Response.AddHeader("Content-Length", bt.Length.ToString());
文件可以在JPG,PDF可以在IE里打开可是EXE.RAR文件就不会出现下载的窗口,。ZIP文件到是可以下载
请问要如何才来实现这样的效果了

解决方案 »

  1.   

    不能根据扩展名或ContentType来确定是否执行(
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="+filename );
    HttpContext.Current.Response.AddHeader("Content-Length", bt.Length.ToString());

      

  2.   

    Path.GetExtention(filename )
    判断扩展名
    再输出下载
    window.open打开jpg
    pdf
    <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="760" height="411" border="0">
      <param name="_Version" value="65539">
      <param name="_ExtentX" value="20108">
      <param name="_ExtentY" value="10866">
      <param name="_StockProps" value="0">
      <param name="SRC" value="a.pdf">
    </object>
      

  3.   


    我本来是想根据ContentType来判断的可是上面说不行不能用这个必须让IE自动判断,我就很郁闷啊
    pdf
    <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="760" height="411" border="0">
    其实不用把东西放在OBJECT里,如果客户端装了PDF阅读器的话不用这样也可以在IE里打开
      

  4.   

    必须让IE自动判断?
    这个就不是你所能控制的了,即使aspx,htm文件,客户端也可以设置成下载的,
    你根本就无法控制
      

  5.   

    只能说,是在ie默认配置的情况下,jpg等能支持的直接打开,其他的下载。
    如果修改ie配置,那就看具体情况了。