为了账号安全,请及时绑定邮箱和手机立即绑定

C# 实现下载csv,数据太多,请求超时,求解决办法!!!急!!!

C# 实现下载csv,数据太多,请求超时,求解决办法!!!急!!!

猛跑小猪 2018-12-07 11:00:25
RT代码: protected void btnReport_Click(object sender, EventArgs e) { IList<Member> StudentList = Search(); string data = ExportCSV(StudentList); string temp = string.Format("attachment;filename={0}", DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"); Response.ClearHeaders(); Response.AppendHeader("Content-disposition", temp); Response.HeaderEncoding = Encoding.GetEncoding("shift-jis"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = Encoding.GetEncoding("shift-jis"); Response.Write(data); Response.Flush(); Response.Close(); IsReport = false; } public string ExportCSV(IList<Member> list) { string data = ""; data = "First name,Last name,DOB,Email,Phone number,Gender,Points,Rank,Address,Suburb,Postcode,School,Avatar Name,Username,Password,DataCreated,Activated status\n"; foreach (Member tb in list) { data += "\"" + tb.FirstName + "\"," + "\"" + tb.LastName + "\"," + "\"" + tb.DateOfBirth + "\"," + "\"" + tb.Email + "\"," + "\"" + tb.PhoneNumber + "\"," + "\"" + (tb.Gender == "F" ? "Female" : (tb.Gender == "M" ? "Male" : "")) + "\"," + "\"" + tb.Points + "\"," + "\"" + (tb.Rank == null ? "" : tb.Rank.Name) + "\"," + "\"" + tb.Address + "\"," + "\"" + tb.Suburb + "\"," + "\"" + tb.Postcode + "\"," + "\"" + (tb.School == null ? "" : tb.School.Name) + "\"," + "\"" + tb.Nickname + "\"," + "\"" + tb.Username + "\"," + "\"" + tb.Password + "\"," + "\"" + tb.DateCreated + "\"," + "\"" + tb.IsActive + "\"," + "\n"; } return data; }
查看完整描述

7 回答

?
函数式编程

TA贡献1807条经验 获得超9个赞

数据库的话用DATAREADER一条条的写进WEB页面中..不要写进LIST中

查看完整回答
反对 回复 2019-01-21
?
Helenr

TA贡献1780条经验 获得超4个赞

没用到Datareader,用的Nhibernate。

查看完整回答
反对 回复 2019-01-21
?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

在web.config中设置一下请求超时设置:

<httpRuntime executionTimeout="300"/>

单位是秒,默认是110秒。

查看完整回答
反对 回复 2019-01-21
?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

非常感谢~已经设置过了,虽说能起作用,但是还是时间超长。

查看完整回答
反对 回复 2019-01-21
?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

非常感谢~同1楼。

查看完整回答
反对 回复 2019-01-21
  • 7 回答
  • 0 关注
  • 553 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信