I have to export the list users as a CSV file.

Here is my Sample.cs

```
   `public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public DateTime DateOfBirth { get; set; }`

```

Here is my controller code and sample data.

```
   `
  private IList<Sample> sample = new List<Sample>
    {
        new Sample {Id=1,Name ="pons",Email="pons@gmail.com"},
        new Sample {Id=2 ,Name="maddy",Email="maddy@hotmail.com"},
        new Sample {Id=3,Name="thom",Email="thom@malinator.com"},
        new Sample {Id=4,Name="gomz",Email="gomz@outlook.com"},
        new Sample { Id=5,Name="vaandu",Email="vaandu@gmail.com"}
    };
   [HttpGet]
    [Route("GetValue")]
    public IActionResult ExportToCSV()
    {

        var builder = new StringBuilder();
        builder.AppendLine("Id,Name,Email");
        foreach (var data in sample)
        {
            builder.AppendLine($"{data.Id},{data.Name},{data.Email}");
        }
        return File(Encoding.UTF8.GetBytes(builder.ToString()), "text/csv", "god.csv");`

```

The above code is expected to return a file (automatically download a csv file).It returns a text instead of a file.
Here is the output of the above code
[![Response to postman by above controller](https://i.stack.imgur.com/XTHUm.png)](https://i.stack.imgur.com/XTHUm.png)

This how it return to my angular request
[![Response b y the above controller to angular request](https://i.stack.imgur.com/ZEAiv.png)](https://i.stack.imgur.com/ZEAiv.png)