p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   Problem with Inline Excel Output Filename (http://p2p.wrox.com/showthread.php?t=55625)

Sir Guso March 20th, 2007 02:27 PM

Problem with Inline Excel Output Filename
I have searched many forums on my problem and tried many things that I have seen but nothing seems to work. So, perhaps I will be lucky and someone will be able to help me.

I have a 1.1 .NET project that I redirect to from another website in order to generate an Excel report. Up until now we have been writing to a file on the server, redirect to that file, then the user can save or open it. That worked finr but can no longer do that and must instead produce the Excel document within the browser using the inline parameter in a Response.AddHeader and giving it a filename. The problem is that this filename is ignored and when the user tries to save the opened Excel file the filename that is there is "Copy of TheInitialAspxPageName.aspx."

I am running it on my PC currently as a test project but I get the same result when I port whatever code to teh actual reporting application and place it on the server to use. My test app has a start page called ReportStart.aspx and all it has is a button that when clicked does a server transfer to a page that is used to figure out what report is coming in so as to send the right variables and then perform another "server.transfer" to the page that generates the Excel output. On that page the Excel output is created and put into a memstream. Below is the latest code (end of Page_Load code) I am trying -- please respond if you have any idea of how to solve this. You will see some commented out lines of what was tried before and also did not help. Thanks.

string textFileParameters = "inline; filename=" + reportName + ".xls";
//Response.Buffer = true;

//Response.ContentType = "application/x-msexcel";
Response.ContentType = "application/msexcel";

//Response.Expires = -1;
//Response.Buffer = true;
Response.Buffer = false;

//Response.ContentType = "application/vnd.ms-msexcel";
//Response.AddHeader("Cache-Control", "max-age=0");

System.IO.MemoryStream memStream = new System.IO.MemoryStream();



Sir Guso March 28th, 2007 10:58 AM

Weel, there have been no responses and I could not get a solution to this problem from anywhere I tried. One place I tried was Microsoft and they instead helped me use "Attachment" successfully by adding a line in the code of the calling page so I no longer had an issue using "Attachment." I guess that is what you have to use to get this to work right. Oh well. I tried.

Kevinmiam May 31st, 2007 08:26 PM

If you use Isapi_Rewrite for IIS, there is a very clean solution to using "inline" and getting the correct file name for the Save As... Dialog.

Instead of making the link to ReportStart.aspx, make it to a fictional Directory like http://mysite/Download Reports/xx/MyFileNameAsIWouldLikeToSeeIt.xls where xx is the information ReportStart needs to be passed as a parameter.

In your httpd.ini for for isapi_rewrite, add a RewriteRule:

RewriteRule ([^.?]*?/)Download Reports/(.*)/(.*) $1ReportStart.aspx?id=$2 [I]

For those of you who don't live and breath Regex:

http://mysite/Download Reports/xx/MyFileNameAsIWouldLikeToSeeIt.xls

gets turned into:


The document should open in your browser. But the URL remains...Click Save As...and the file name is MyFileNameAsIWouldLikeToSeeIt.xls

All times are GMT -4. The time now is 04:06 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.