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?
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?
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()
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();