Click here to Skip to main content
15,561,948 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am writing a code to download an excel file from a location. The code is as follows:

SQL
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()


I pass the file server location in reportPhysPath and the file-name to be opened is passed in ReportFileName.

The Issue is:
When I download an excel file, it opens the file in excel with a name of "Download.aspx" , i.e. the name of the page where the function for downloading the file is written. The name of the excel file should be have been displayed. Suppose the file name in the file server is "mike1.xls", the file name while opening the page should also be "mike.xls" instead of "Download.aspx"

This causes an error message displayed when I try to download another file(mike2.xls) with the current file(mike1.xls) already open in Microsoft Office Excel 2007. The error message says that a file with name "Download.aspx" is already open.


Please help me solve this. Thanks in Advance :)
Posted

VB
Response.Clear()
            Response.Buffer = True
            Response.AddHeader("content-disposition", "attachment;filename=ClientPayFollowUp " & DrpClient.Text.ToString & ".xls")
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.ContentType = "application/vnd.Excel"

this may help you....
 
Share this answer
 
Hi Devang Vaja,

I tried to implement this code in my web application. The excel file is opening but the name while opening the code is still "download.aspx".

Can you please tell me whether you implemented this code on the download button code-behind directly or in the code-behind of a seperate web page.


Thanks !!!
 
Share this answer
 
Comments
Devang Vaja 3-Sep-12 4:35am    
i have tried it in code behind directly in .aspx.vb
in Protected Sub BtnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnExport.Click
MikeRox89 4-Sep-12 8:20am    
Hi Devang,I got the solution to my problem. I was using
Response.AddHeader("content-disposition", "inline; filename=" & ReportFileName)

Modified this line to :
Response.AddHeader("content-disposition", "attachment; filename=" & ReportFileName)

Making this file as attachment solved the issue...

Thanks !!!! :)
Devang Vaja 4-Sep-12 8:22am    
Your Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900