private void Export(bool optionCustomersWithOrders, bool optionNewsletterSubscribers) { List <object> exportList = new List <object>(); if (optionNewsletterSubscribers) { List <NewsLetter> newsletterMailingList = NewsLetter.NewsLetterMailingList(optionCustomersWithOrders); exportList = newsletterMailingList.ConvertAll <object>(delegate(NewsLetter g) { return((object)g); }); } else { List <GridCustomer> customerList = new List <GridCustomer>(); if (optionCustomersWithOrders) // filter to customers only with orders { var allCustomers = GridCustomer.GetCustomers(); foreach (var c in allCustomers) { Customer customer = new Customer(c.CustomerID); if (customer.HasOrders()) { customerList.Add(c); } } } else // return all customers { customerList = GridCustomer.GetCustomers(); } exportList = customerList.ConvertAll <object>(delegate(GridCustomer g) { return((object)g); }); } StringBuilder strMailingList = new StringBuilder(); Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=MailingList.csv"); Response.ContentType = "text/csv"; Response.AddHeader("Pragma", "public"); strMailingList.Append(CSVExporter.ExportListToCSV(exportList)); Response.Write(strMailingList.ToString()); Response.End(); }