Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
file name: abc.aspx

my code:
C#
string Path = @"E:\documents\Data20160129110355.xls";
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename="+path+"");
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();

On click of "Open" it will open the file successfully but the header of the file are not showing "Data20160129110355.xls". It's showing abc.aspx.

How to solve this problem please reply.
Posted
Updated 31-Jan-16 20:06pm
v2

1 solution

Try with below code:
C#
string Path = @"E:\documents\Data20160129110355.xls";
string sFileName = "Data20160129110355.xls";
Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName);
HttpContext.Current.Response.RedirectLocation = url;
HttpContext.Current.Response.TransmitFile(Path);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
 
Share this answer
 
Comments
Member 12299286 1-Feb-16 2:08am    
@Manas_Kumar: I tried your code but it's not working.
[no name] 1-Feb-16 2:12am    
By the way, what is the file name you are getting now?
Member 12299286 1-Feb-16 2:13am    
The file header name is abc.aspx
For "Save" and "Save As" it's working fine.
This problem happening only for "Open".
[no name] 1-Feb-16 2:18am    
What is purpose "RedirectLocation" in your code? Because it gets or sets the value of the HTTP Location header.

Can you just comment and try it again.
Member 12299286 1-Feb-16 2:19am    
i removed that line of code.
but still it's not working.

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