Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am working on an ASP.NET application using VS 2008. I have generated an Excel file through code and saved it on the server. I have used the following code.

MIDL
Response.ContentType = "Excel";
      Response.AppendHeader("Content-Disposition", "attachment; filename=Report.xls");
      Response.TransmitFile(Server.MapPath("~//Report.xls"));
      Response.End();


On my end, it works fine but when I publish the site on the server, it doesn't open the file. Instead it gives the message "Page not found".

Please help!
Posted
Updated 23-Aug-10 8:15am
v3
Comments
Dalek Dave 23-Aug-10 9:11am    
Minor Edit for Grammar and Spelling.
Dalek Dave 23-Aug-10 9:12am    
Reason for my vote of 5
Well phrased and presented question.

1 solution

The error lies here:

C#
Response.TransmitFile(Server.MapPath("~//Report.xls"));


The URL to access the file is not forming correctly. At times, after hosting, the path of files are a little different than while in development.

Try using this tip[^] for resolving the URLs.
 
Share this answer
 
v2
Comments
Dalek Dave 23-Aug-10 9:12am    
Good Call! Have some points, helped me too!

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