Open in New Window problem


#1

I have an ASP application. From the ASP application, I am launching an ASP.Net webpage and having the .Net page parse the ASP page that opened it. From there, I am recreating the html layout in Excel.

My question is this: When calling the .Save() function in ASPOSE.Excel, it seems to stop some of the page processing and I am unable to close the .Net page. This is a problem as I would like only the ASP page and the excel document open when it has completed.

I cannot use the OpenInWindow version of the Save command because there are times we want the document to load in excel, and also a client has a custom version of IE which will open the document in excel no matter what.

How can I close the window which opens the ASPOSE.Excel page?

Thanks,
Neil


#2

If you don't call Excel.Save method, how do you close the .NET page?

When calling Excel.Save method, Aspose.Excel internally call Response.End method. Otherwise, the web page content may mess up with the Excel file.

For your case, I think you can save the Excel file on the server and provide a hyperlink to your users.


#3

Is there any way to force the .Save method to NOT call Response.End? I have tried using the .Save() methods that allow me to supply my own HttpResponse but I have thus far been unable to get this to work correctly. In other words…I’m looking to do 1 of 2 things.


1) Not have the response.end called after a save
2) Navigate to a different page after the save method is called (via a Response.Redirect perhaps).

Are there any options out there for me? Am I just not using the correct code? Could you give me an example? I’m working in VB.Net

Thanks,
Neil


#4

Hi Neil,

The following sample code is how Aspose.Excel stream the binary data to client. You can tailor it to serve your need:

MemoryStream stream = new MemoryStream();
excel.Save(stream, FileFormatType.Default);

byte[] data = stream.ToArray();

this.Response.ContentType = “application/xls”;

if(saveType == SaveType.OpenInExcel)
{
//OpenInExcel
Response.AddHeader( “content-disposition”,“attachment; filename=book1.xls”);
}

else
{
//OpenInBrowser
Response.AddHeader( “content-disposition”,“inline; filename=book1.xls”);
}

Response.BinaryWrite(data1);
Response.End();


#5

This looks like it is exactly what I need. I’ll try this tomorrow and see if it solves my issue.

Thank you for the very quick reply!

-Neil

Quick-note for anyone reading Laurence’s response above: Response.BinaryWrite(data1); should be Response.BinaryWrite(data); as defined by his declared byte array on line 4 of the code.