小弟网站中的常规文件比如.txt .exe .jpg等可以通过WebClient正常下载,但.bat文件和一种扩展名为.tvt的文件无法下载,提示404错误。请问如何在web.config中设置以使得这些特殊类型文件可以下载?

解决方案 »

  1.   

    试试以下的:
            string filePath = Server.MapPath("~/文件目录/文件名.doc");
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("文件名.doc", System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
      

  2.   

    不是程序的问题,IIS有限制。
      

  3.   

    压缩文件实现下载
    如System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
      Process1.StartInfo.FileName = "Winrar.exe";
      Process1.StartInfo.CreateNoWindow = true;
    或输出二进制流数据