猿问

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

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;
    }
猛跑小猪
浏览 554回答 7
7回答

函数式编程

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

Helenr

没用到Datareader,用的Nhibernate。

海绵宝宝撒

在web.config中设置一下请求超时设置: <httpRuntime executionTimeout="300"/> 单位是秒,默认是110秒。

白猪掌柜的

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

繁星点点滴滴

非常感谢~同1楼。
随时随地看视频慕课网APP
我要回答