Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response Content type as CSV

Tags:

http

csv

asp.net

I need to send a CSV file in HTTP response. How can I set the output response as CSV format?

This is not working:

Response.ContentType = "application/CSV"; 
like image 516
balaweblog Avatar asked Dec 26 '08 09:12

balaweblog


People also ask

What does text CSV mean?

A CSV (comma-separated values) file is a text file that has a specific format which allows data to be saved in a table structured format.

What is CSV format example?

A CSV file is a list of data separated by commas. For instance, it may look like the following: Name,email,phone number,address. Example,[email protected],555-555-5555,Example Address.

What is the difference between text CSV and application CSV?

If a server says "This data is of type text/csv" the client can understand that can render that data internally, while if the server says "This data is of type application/csv" the client knows that it needs to launch the application that is registered on the OS to open csv files.


2 Answers

Using text/csv is the most appropriate type.

You should also consider adding a Content-Disposition header to the response. Often a text/csv will be loaded by a Internet Explorer directly into a hosted instance of Excel. This may or may not be a desirable result.

Response.AddHeader("Content-Disposition", "attachment;filename=myfilename.csv"); 

The above will cause a file "Save as" dialog to appear which may be what you intend.

like image 75
AnthonyWJones Avatar answered Sep 25 '22 12:09

AnthonyWJones


MIME type of the CSV is text/csv according to RFC 4180.

like image 35
sastanin Avatar answered Sep 22 '22 12:09

sastanin