IE6下为什么有的文件能下载,有的文件就下载不了(页面变为空白)。而IE7、IE8则都可以
下载代码如下
1 /// <summary>
2 /// 文件下载
3 /// </summary>
4 /// <param name="curPage">Page页面</param>
5 /// <param name="fileName">客户端显示的文件名</param>
6 /// <param name="filePath">完整的文件路径</param>
7 /// <param name="speed">速度</param>
8 /// <returns>是否下载成功</returns>
9 public static bool DownloadFile(Page curPage, string fileName, string filePath, long speed)
10 {
11 try
12 {
13 HttpResponse response = curPage.Response;
14 HttpRequest request = curPage.Request;
15 FileStream myFile = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
16 BinaryReader br = new BinaryReader(myFile);
17 try
18 {
19 response.AddHeader("Accept-Ranges", "bytes");
20 response.Buffer = false;
21 long fileLength = myFile.Length;
22 long startBytes = 0;
23
24 double pack = 10240; //10K bytes
25 //int sleep = 200; //每秒5次 即5*10K bytes每秒
26 int sleep = (int)Math.Floor(1000 * pack / speed) + 1;
27 if (request.Headers["Range"] != null)
28 {
29 response.StatusCode = 206;
30 string[] range = request.Headers["Range"].Split(new char[] { '=', '-' });
31 startBytes = Convert.ToInt64(range[1]);
32 }
33 response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
34 if (startBytes != 0)
35 {
36 //Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
37 }
38 response.AddHeader("Connection", "Keep-Alive");
39 response.ContentType = "application/octet-stream";
40 response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
41
42 br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
43 int maxCount = (int)Math.Floor((fileLength - startBytes) / pack) + 1;
44
45 for (int i = 0; i < maxCount; i++)
46 {
47 if (response.IsClientConnected)
48 {
49 response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString())));
50 System.Threading.Thread.Sleep(sleep);
51 }
52 else
53 {
54 i = maxCount;
55 }
56 }
57 }
58 catch
59 {
60 return false;
61 }
62 finally
63 {
64 br.Close();
65
66 myFile.Close();
67 }
68 }
69 catch
70 {
71 return false;
72 }
73 return true;
74 }
不能下载的机器是否安装了一些下载工具,如迅雷等。
这个我想看你的客户用的是什么样子的IE ,如果>6的话,我想你的这个就不是问题。你可以尝试着,让客户升级他的IE
不能下载的文件的扩展名是什么?