Convert A Generic List To CSV File In C#

This is an example of how to convert a generic list to a dynamic downloadable .csv file using C#, the CsvHelper library and the FileStreamResult.

Download the repo and run the full project solution from Github

In this example a request comes into the controller, we create a generic list of type ListItem, created a memory stream and using the CsvWriter library  return a dynamic .csv file to the browser.

Step 1: Create the generic list class
This class will hold our generic list items. This can be whatever data you need.

public class ListItem
    public int Id { get; set; }
    public string Name { get; set; }

Step 2: Create the MVC action to return the CSV file
This action method creates the generic list, writes it to memory with help from the CsvHelper library and returns the FileStreamResult back to the browser.

//Action Method for your controller
public ActionResult ConvertToCSV()
    //Create the test list
    var list = new List<ListItem>()
        new ListItem(){Id = 1, Name = "Jerry"},
        new ListItem(){Id = 2, Name="George"},
        new ListItem(){Id = 3, Name="Kramer"},
        new ListItem(){Id = 4, Name = "Elaine"}

    byte[] result;
    using (var memoryStream = new MemoryStream())
        using (var streamWriter = new StreamWriter(memoryStream))
            using (var csvWriter = new CsvWriter(streamWriter))
                result = memoryStream.ToArray();

     return new FileStreamResult(new MemoryStream(result), "text/csv") { FileDownloadName = "filename.csv" };

h/t to this StackOverflow post

Download the repo and run the full project solution from Github


TestFlight is currently unavailable. Please try again later.

While testing a new iOS build for Tap In Guide I started getting this error when trying to open the app from TestFlight on my phone “TestFlight is currently unavailable. Please try again later.”

After trying again and again and again I still wasn’t able to open the new build — or any build — in TestFlight. I looked over Stack Overflow and the rest of the Internet for suggestions and a lot of people were having the same issue but with quite a few different solutions.

These are some of the ways people have fixed or gotten around the error “TestFlight is currently unavailable. Please try again later.” .

My solution

  • Remove myself from Testers (iTunes Connect → Your App → TestFlight → iTunes Connect Users → Testers → click the red circle on the line with your user.
  • Readded myself as an Tester (Make sure “send notification” is checked).
  • Open the TestFlight invite email notification from my phone.
  • Click “View in TestFlight” button from the email.
  • Done. This should open TestFlight on your phone and give you the option to install the new build.

Other solutions

Those are all the different ways to fix the error that I tried and have worked for other people. If you fix this issue using another method, please let me know and I’ll add it to this list.

Good luck!