Download csv file directly in web browser

0

I have an aspx web application with C # code behind it. What I try to do when the user manually clicks on the Download button, independent of the browser, the file can be downloaded immediately in the download directory.

How can I do this?

    
asked by A arancibia 05.02.2016 в 17:47
source

2 answers

1

To download the file you could use something like

Response.Clear();
Response.ContentType = "text/csv";
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));

Response.WriteFile("ruta archivo");

Response.End();

Imagine the csv is in a file so use the Response.WriteFile() but you can also use the Response.BinaryWrite()

    
answered by 05.02.2016 / 17:54
source
0

To download a .csv you can also use a ContentType="text/plain"

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType="text/plain";
response.AddHeader("Content-Disposition",  "attachment; filename=" + nombreArchivo + ";");
response.TransmitFile(Server.MapPath("miArchivo.csv"));
response.Flush();    
response.End();
    
answered by 05.02.2016 в 18:34