We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to execute next line of codes after invoking Workbook.SaveAs() method in XlsIO web application?

By default, the code after the SaveAs method won’t execute in Web platforms. This is because, Response.End() method has been invoked inside IWorkbook.SaveAs to download the generated Excel document. However, this can be resolved by saving workbook object in a memory stream and execute the code after that. Finally, send the stream into the method as given in the code snippet to achieve the requirement. 

 

C#

 

VB

 

The sample which illustrates the above behavior can be downloaded here.

Article ID: Published Date: Last Revised Date: Platform: Control:
8070 11/15/2017 11/15/2017 ASP.NET Web Forms XlsIO
Did you find this information helpful?
Comments
Michal Levý Nov 28, 2017

Is this information still relevant ?

I'm using current XslIO from nuget and it seems my code after SaveAs is executed (+ i don't see any ThreadAbortException so i doubt Response.End() call is used...)

Reply
Mohan Chandran [Syncfusion] Dec 04, 2017

Hi Michal,

 

This KB article is given for Web applications in which the generated Excel document is saved using Http response and to execute some code after that response. This is not applicable for other platforms.

 

Regards,

Mohan Chandran.

Reply
Michal Levý Jan 17, 2018

I can read, i know this article is for ASP.NET. 

I'm using SaveAs in ASP.NET application and i still don't see any ThreadAbortExceptions, if i run my app in debugger and put breakpoint after line calling SaveAs, the break point is hit and code is executed.

Thats why i think this article is no longer true...

Mohan Chandran [Syncfusion] Jan 23, 2018

Hi Michal,

While saving the workbook in a memory stream, the Thread abort exception will not be thrown and the code in the next line will be executed. But, the exception will be thrown if the workbook is saved into a downloadable Excel file using IWorkbook.SaveAs method. To execute the code after saving the Excel file, we have provided the SendStream(MemoryStream stream, string fileName, ExcelVersion version) method in this article. The following code snippet will abort the current thread in a web application.

 

Code Snippet:

workbook.SaveAs("Sample.xlsx", ExcelSaveType.SaveAsXLS, Response,ExcelDownloadType.Open);

 

However, this information is not mentioned in this article. We will update the content with these information soon.

 

Regards,

Mohan Chandran.

Reply
Michal Levý Feb 07, 2018

Hi Mohan

Im using "wb.SaveAs(fileName, ExcelSaveType.SaveAsXLS, response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013);" with IWorkbook.Version set to ExcelVersion.Excel2013

Im not seeing any ThreadAbortException and next line is executed.

Maybe its because im calling SaveAs in ASP MVC controller action and not in WebForms. Althrough article is tagged as "Platform = ASP.NET Web Forms", from the text itself (and article name) it may seem as this applies to all ASP.NET web applications ("By default, the code after the SaveAs method won’t execute in Web platforms") which is not true appearently...


Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon