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贡献1809条经验 获得超8个赞
在web.config中设置一下请求超时设置:
<httpRuntime executionTimeout="300"/>
单位是秒,默认是110秒。
- 7 回答
- 0 关注
- 553 浏览
添加回答
举报
0/150
提交
取消