• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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.
0
ravindra333
Asked:
ravindra333
  • 3
1 Solution
 
GiftsonDJohnCommented:
Use the following url

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24323753.html?cid=237#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"
0
 
GiftsonDJohnCommented:
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();
0
 
GiftsonDJohnCommented:
Sorry one more correction

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; 2008-10-17--11-57-26.csv");
Response.WriteFile(str);
Response.End();
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now