[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

Client download .csv file from server using Response.TransmitFile

I am using the code below to enable clients to download a .csv file from my server.

The problem I am having is that when the file is saved to the client computer the file name is prefixed and suffixed with an underscore which leads to a file type of .csv_ which is obviously not a recognised file type.

How can I strip the underscores from the file name at the transmit stage?

        Dim FileName As String = LstBox1.SelectedItem.ToString
        Dim FilePath As String = "~/temp" & FileName
        Response.Clear()
        Response.ContentType = "text/csv"
        Response.AddHeader("Content-Disposition", "attachment; filename=\" & FileName & "\")
        Response.TransmitFile(FilePath)
        Response.End()
0
taylor99
Asked:
taylor99
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
call replace inline on the filename.
Response.AddHeader("Content-Disposition", "attachment; filename=\" & FileName.Replace("_","") & "\")
0
 
taylor99Author Commented:
see http://forums.asp.net/p/1598575/4065473.aspx#4065473 for resolution to this issue
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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