I want to return a .csv file from an ASP.NET MVC 3 ActionResult in the controller. I've found other examples of people doing this out on the web, but it seems like they have an ASP data structure that they are converting to csv.
My situation is a little different. I actually have a file on the local drive called myfile.csv. I want to return the file so the user can download it as a .csv.
Here is my code:
public ActionResult GetCSVFile()
{
return File(service.initiateCsvGeneration(1), "text/csv");
}
initiateCsvGeneration returns a string with a path to the filename. My filename already has the .csv extension and it is already in a comma delimited format. For some reason it is chopping of the .csv extension in my filename. Instead of allowing the user to download it as myfile.csv, it makes them download it as myfile although the actual disk file has the .csv extension and it is also present in the string that is in initiateCsvGeneration.
What else could be wrong here?