0

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();
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JReam
  • 898
  • 2
  • 13
  • 28
  • what does the actual data look like.. are there any other delimiters that are throwing off the returning of the data..? have you used the debugger to step through the code.. what if you export the same data to a DataTable to see if you can notice any strange characters being returned.. can you show an example of what the data looks like..? – MethodMan Sep 04 '16 at 03:21
  • Sweet MethodMan responded :) The data consists of dates, int's, strings etc. Think of when you register for a class, the data that is collected about you as a student. Name, email, address, course name, start date, end date, price, city, state country zip etc. As I mentioned, when ran locally in localhost/sql express, the data outputs as expected and includes all records expected. When pushed to Azure, the output is as expected but it only outputs 350 records. – JReam Sep 04 '16 at 15:35

0 Answers0