Link to home
Start Free TrialLog in
Avatar of taylor99
taylor99

asked on

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()
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

call replace inline on the filename.
Response.AddHeader("Content-Disposition", "attachment; filename=\" & FileName.Replace("_","") & "\")
ASKER CERTIFIED SOLUTION
Avatar of taylor99
taylor99

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