Want to download the file through code with the original file name

Asked By 60 points N/A Posted on -



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)

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.


Answered By 0 points N/A #199021

Want to download the file through code with the original file name


I hope to provide this solution in order to fix your issue. The solution can be done by changing your excel settings in the Option tabs and then choose not to verify the opening of new spreadsheets.
The second solution can be done by simply changing the filename and then the file can be opened smoothly.
With my best regards,
Don Muench

Login/Register to Answer

Related Questions