Want to download the file through code with the original file name
Hello,
I wrote this code which I could use to download an excel file from a particular location;
Select Case strFileType
Case "txt" : Response.ContentType = "text/plain"
Case "xls", "csv" : Response.ContentType = "application/x-msexcel"
Case Else
Response.ContentType = "application/octet-stream"
End Select
Response.AddHeader("content-disposition", "inline; filename=" & ReportFileName) Response.TransmitFile(reportPhysPath & ReportFileName)
Response.End()
reportPhysPath is the file server location and ReportFileName is the name the file is supposed to open.
My question then is: when I eventually downloaded the Excel file, the file was open with the name "Download.aspx” (this is the web page where the function of downloading the file is written) instead I wanted the name of the Excel filed displayed. For example if the file name is “Exmple1.xls”the downloaded file should be displayed as “Exmple1.xls”and no as "Download.aspx" which causes a problem when I download another file with the current download file open as I get this error message that “Download.aspx is already open” Does anyone have an idea how I can fix this?
The file you are trying to open, ‘Download.xls’, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
Please help me.
Thanks.