IE6下载excel文件名截断问题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 System.Text.Encoding code = System.Text.Encoding.GetEncoding("UTF-8");
2 HttpContext.Current.Response.ContentEncoding = code;
3 HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.Default;
4
5 if (fileName.Contains(".xls") || fileName.Contains(".xlsx"))
6 {
7 HttpContext.Current.Response.ContentType = "application/vnd.ms-excel;chartset=utf-8";
8
9 }
10
11 else
12 {
13 HttpContext.Current.Response.ContentType = "application/x-msdownload";
14 }
15 HttpContext.Current.Response.AppendHeader("Connection", "keep-alive");
16
17
18
19 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
20
21 HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
22
23 byte[] fileBuffer;
24
25 if (fileSize > 0)
26 {
27 fileBuffer = new byte[fileSize];
28 fileStream.Read(fileBuffer, 0, (int)fileSize);
29
30 }
31 else
32 {
33 //文件流长度为空时,构造一个不为0的字节数组
34 fileBuffer = new byte[1];
35 }
36 fileStream.Close();
37 HttpContext.Current.Response.BinaryWrite(fileBuffer);
38
39 HttpContext.Current.Response.Flush();
40 HttpContext.Current.Response.End();
2 HttpContext.Current.Response.ContentEncoding = code;
3 HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.Default;
4
5 if (fileName.Contains(".xls") || fileName.Contains(".xlsx"))
6 {
7 HttpContext.Current.Response.ContentType = "application/vnd.ms-excel;chartset=utf-8";
8
9 }
10
11 else
12 {
13 HttpContext.Current.Response.ContentType = "application/x-msdownload";
14 }
15 HttpContext.Current.Response.AppendHeader("Connection", "keep-alive");
16
17
18
19 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
20
21 HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
22
23 byte[] fileBuffer;
24
25 if (fileSize > 0)
26 {
27 fileBuffer = new byte[fileSize];
28 fileStream.Read(fileBuffer, 0, (int)fileSize);
29
30 }
31 else
32 {
33 //文件流长度为空时,构造一个不为0的字节数组
34 fileBuffer = new byte[1];
35 }
36 fileStream.Close();
37 HttpContext.Current.Response.BinaryWrite(fileBuffer);
38
39 HttpContext.Current.Response.Flush();
40 HttpContext.Current.Response.End();
posted on 2010-03-11 17:17 MoonWalker 阅读(517) 评论(0) 编辑 收藏 举报