I have the following controller and service that returns data to the user to populate an Excel file. In LocalHost with SQL Server Express, it works great.
However.... it's only writing 350 records when running from a cloud environment. Any idea why it caps the response at 350?
[HttpPost]
[ValidateAntiForgeryToken]
public void Index(ReportsViewModel vm)
{
// additional code removed for brevity
if (ModelState.IsValid)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ILT & eLearning Registrations - " + DateTime.Now.ToShortDateString() + ".xls");
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
ReportService reportService = new ReportService();
if (vm.Report == "Registrations")
{
reportService.DownloadRegistrationsReport(vm, Response);
}
}
ViewBag.Reports = "active";
}
public void DownloadRegistrationsReport(ReportsViewModel vm, HttpResponseBase Response)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var registrations = (from r in db.Registrations
where (vm.BusinessUnit == "All" || r.BusinessUnit.Equals(vm.BusinessUnit)) &&
(vm.Region == "All" || r.Region.Equals(vm.Region)) &&
(vm.DeliveryType == "All" || r.DeliveryType.Equals(vm.DeliveryType)) &&
(vm.CustomerTypeName == "All" || r.CustomerTypeName.Equals(vm.CustomerTypeName)) &&
r.EndDate >= vm.StartDate &&
r.EndDate <= vm.EndDate
select new
{
RegistrationId = r.RegistrationId,
ScheduleId = r.ScheduleId,
CourseId = r.CourseId,
RegistrationDate = r.RegistrationDate,
// code removed for brevity
}).ToList();
WriteTsv(registrations, Response.Output);
Response.End();
}
}
public void WriteTsv<T>(IEnumerable<T> data, TextWriter output)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.DisplayName); // header
output.Write("\t");
}
output.WriteLine();
foreach (T item in data)
{
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.Converter.ConvertToString(
prop.GetValue(item)));
output.Write("\t");
}
output.WriteLine();
}
}