406 Stimmen

Antwort Inhaltstyp als CSV

Ich muss eine CSV-Datei als HTTP-Antwort senden. Wie kann ich die Ausgabeantwort als CSV-Format festlegen?

Das funktioniert nicht:

Response.ContentType = "application/CSV";

0voto

Suresh Kamrushi Punkte 14582

Für C# MVC 4.5 müssen Sie wie folgt vorgehen:

Response.Clear();
Response.ContentType = "application/CSV";
Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + ".csv\"");
Response.Write(dataNeedToPrint);
Response.End();
return new EmptyResult();  //this line is important else it will not work.

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X