ravindra333
asked on
how to download file with extension of .csv in asp.net
Hi,
I have .csv extension file. I am trying to download that file when I click a link button.
My link button is in "view.asp" page. When I click on this link button it will redirect to "download.aspx" page.
Code in download.aspx page is below:-
-------------------------- ---------- ---------- ----
Response.ContentType = "text/csv";
string str = @"C:\Dev\TaxSegExpress\adm in\downloa d\2008-10- 17--11-57- 26.csv";
Response.AppendHeader("Con tent-Dispo sition", attachment;+ str);
Response.TransmitFile(str) ;
Response.End();
Now my issue is, when I click on link button it is opening a Popup window with an extension of .aspx.
My file extension is .csv but it is opening with .aspx.
Can you please say me how to download file with extension of .csv in asp.net.
I have .csv extension file. I am trying to download that file when I click a link button.
My link button is in "view.asp" page. When I click on this link button it will redirect to "download.aspx" page.
Code in download.aspx page is below:-
--------------------------
Response.ContentType = "text/csv";
string str = @"C:\Dev\TaxSegExpress\adm
Response.AppendHeader("Con
Response.TransmitFile(str)
Response.End();
Now my issue is, when I click on link button it is opening a Popup window with an extension of .aspx.
My file extension is .csv but it is opening with .aspx.
Can you please say me how to download file with extension of .csv in asp.net.
Okay, your issue is you have to clear the response object by using
Response.Clear()
It should be the first line.
Response.Clear();
Response.ContentType = "text/csv";
string str = @"C:\Dev\TaxSegExpress\adm in\downloa d\2008-10- 17--11-57- 26.csv";
Response.AppendHeader("Con tent-Dispo sition", attachment;+ str);
Response.TransmitFile(str) ;
Response.End();
Response.Clear()
It should be the first line.
Response.Clear();
Response.ContentType = "text/csv";
string str = @"C:\Dev\TaxSegExpress\adm
Response.AppendHeader("Con
Response.TransmitFile(str)
Response.End();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/24323753/asp-net-vb-net-export-dataset-to-excel.html?cid=237&anchorAnswerId=24147438#a24147438
here you have to do a minor modification
instead of these lines
Dim attachment As String = "attachment; filename=userlist.xls"
Response.ClearContent()
Response.AddHeader("conten
Response.ContentType = "application/vnd.ms-excel"
you have to use
Dim attachment As String = "attachment; filename=attachment.csv"
Response.ClearContent()
Response.AddHeader("conten
Response.ContentType = "text/plain"