Link to home
Start Free TrialLog in
Avatar of ravindra333
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\admin\download\2008-10-17--11-57-26.csv";
Response.AppendHeader("Content-Disposition", 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.
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

Use the following url

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("content-disposition", attachment)
        Response.ContentType = "application/vnd.ms-excel"

you have to use

Dim attachment As String = "attachment; filename=attachment.csv"
        Response.ClearContent()
        Response.AddHeader("content-disposition", attachment)
        Response.ContentType = "text/plain"
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\admin\download\2008-10-17--11-57-26.csv";
Response.AppendHeader("Content-Disposition", attachment;+ str);
Response.TransmitFile(str);
Response.End();
ASKER CERTIFIED SOLUTION
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial