« Why Grandma should not do sky diving | Comparision between C# and JAVA »

export to excel but in new page

by Vahid 20. January 2009 05:42

in the last sub system which we were working on, there was requirement to export the result of a query which is from oracle database and is displayed in an asp.net data grid into excel file. but the component we are using for export to excel functionality gets the collection as input parameter and export the data to excel file and write the excel file into response object of the asp.net. this means once the functionality is invoked, a dialog box will be displayed asking Open the file, save the file of cancel the operation. no issue with save and cancel. but when they clicked on the open it opens the excel file in the same browser window where they were viewing the page and they close the window once they were through with viewing the excel file. this means they close the application.

now they needed the excel file be opened in a new window so that they will not loos their application states. what we did to do so is a little bit tricky. in the query page when user clicks on export to excel button we save the data to be exported in an asp.net session state and open a new browser on the user’s machine using following code :

BaseList result = GetInvoices(p);

Session[“exceldata”] = result;

Response.Write("<Script>window.open('ExcelExport.aspx')</Script>");

and we also moved the export to excel logic to the ExcelExport.aspx page

try

{

if (Session[“exceldata”] != null)

{

BaseList result = (BaseList)Session[“exceldata”];if (result.Count > 0)

{

ExportToExcel(ExportToExcelContent(result));

}

}

}

catch (Exception)

{

throw;

}

finally

{

Session[“exceldata”] = null;

}

.Net | Technical

Comments (0)

Related posts

Optimizing Silverlight pages to be search engine friendlyrecently i was involved in development of an web application whose interface was based on Microsoft …Export to PDF, Excel and Image in asp.netExport html and other resources to pdf, excel and imageDifferences between asp.net web Site and asp.net Web ApplicationHave ever wondered what the differences between 2 types of asp.net web projects in visual studio 200…

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen