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()
MySQL ServerASP.NET Programming

Avatar of undefined
Last Comment
taylor99

8/22/2022 - Mon
Kyle Abrahams

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy