我知道做个超链就能下载了,可问题是如果遇到下载文件是.TXT.JPG等,会直接跳转到相关图片,文字页面,请问这应该如何避免?

解决方案 »

  1.   

    下面方法,Insus.NET测试过您相关的问题,没有遇上过.
    http://www.cnblogs.com/insus/articles/1411761.html
      

  2.   

    StringWriter sw = new StringWriter(); 
    sw.WriteLine(""); 
    sw.Close(); 
    Response.Clear(); 
    Response.AddHeader("Content-Disposition", "attachment; filename=test.txt"); 
    Response.ContentType = "application/ms-excel"; 
    Response.ContentEncoding = Encoding.GetEncoding("gb2312"); 
    Response.Write(sw); 
    Response.End(); 
    通过输入流实现下载
    参考
      

  3.   

    Response.ContentType = "Application/octet-stream
      

  4.   

    貌似把文件的ContentType属性改一下就可以当成文件下载了。 不过碰到一些比较另类的浏览器还是会直接显示出来,比如Chrome