thread aborted error on save

I'm starting with a Word template and populating it with data. I am then saving the files to the temp folder, and opening it in the browser. I really don't need to save a physical file, but can't seem to send a stream to the browser.

I create the word document with this:
     Dim document As New WordDocument("c:\mypath\myfile.dotx")

after populating the document with data, I execute this line (per https://help.syncfusion.com/file-formats/docio/loading-and-saving-document?cs-save-lang=1&cs-lang=vb ):
     document.Save("c:\mypath\myNewFileName.docx", FormatType.Docx, response, HttpContentDisposition.InBrowser)
and get a thread-aborted error. 


How can I stream the document to the client browser without creating a thread-aborted error?




10 Replies 1 reply marked as answer

MR Manikandan Ravichandran Syncfusion Team June 2, 2020 02:46 PM UTC

Hi Bert,

Thank you for contacting Syncfusion support.

We are unable to reproduce the mentioned issue at our end. For your reference we have attached the sample which we have tried at our end to reproduce the mentioned issue.

Sample Link
https://www.syncfusion.com/downloads/support/forum/154801/ze/F154801-1793131193

So, kindly provide us complete sample used at your end to reproduce the mentioned issue, so that we can proceed further to analyse and update you with the appropriate details.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.

Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran
 



BS Bert Sirkin June 2, 2020 04:38 PM UTC

Using the code below, I run into 2 major issues (although a document is sent to the browser):

1) When the "document.Save" is called, it generates a runtime error (thread aborted); and
2) If I trap the error and ignore it, I get a prompt to open the document. If I try to open it, I get a dialog indicating: "We're sorry. We can't open Sample.docx because we found a problem with its contents. The file is corrupt and can't be opened.". 

If I click OK, I get another dialog indicating: 

If I click "Yes", it opens.


Here is the "hello-world" code:
--------------------------------------------------
Imports Syncfusion.DocIO
Imports Syncfusion.DocIO.DLS

Public Sub CreatDoc()
            Dim sTemplateDoc As String = Server.MapPath("~/Template/TemplateTest.dotx")
            Dim document As WordDocument = New WordDocument(sTemplateDoc, FormatType.Docx)
            document.Save("Sample.docx", FormatType.Docx, HttpContext.Current.Response, HttpContentDisposition.Attachment)
            document.Close()
End Sub
--------------------------------------------------

What do I need to do to avoid the "thread-aborted" and "corrupt file" errors??



MR Manikandan Ravichandran Syncfusion Team June 3, 2020 09:30 AM UTC

Hi Bert,

Thank you for your update.

We have tried to reproduce the reported issue using the provided code example, but it was working fine as expected in our end and the sample which we have used in our end to reproduce the issue can be downloaded from the following link.

Sample link:
https://www.syncfusion.com/downloads/support/forum/154801/ze/ASPNetWebFormsVB1724933921

If you are still facing the same issue, then kindly share the modified sample of above which will helpful for us to provide you the appropriate solution at the earliest. 


Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran
 



BS Bert Sirkin June 3, 2020 01:09 PM UTC

It's VERY easy to reproduce. I've attached a complete project - you'll just need to add references to the Syncfusion files (Syncfusion.Docio.Base), as I had to remove them to keep the ZIP file under the 30mb max.

Attachment: SyncfusionDocIoTest2_7c1c3bf7.zipx


MR Manikandan Ravichandran Syncfusion Team June 4, 2020 05:50 PM UTC

Hi Bert,

Thank you for your update.

We can reproduce the reported thread aborted exception in our end, and we suspect it to be a defect. We will validate this issue and update you with more details on 8th June 2020.

Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran



MR Manikandan Ravichandran Syncfusion Team June 9, 2020 09:00 AM UTC

Hi Bert,

Thank you for your patience.

On further checking the reported issue, we have used HttpResponse.End Method in the saving of word document in Asp.Net MVC platform. This method Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event. And also, this method tries to raise a ThreadAbortException exception. So, we suggest you to avoid using try and catch statement while save and returing the word document in MVC platform.

Please refer the below link to know more about the same.
https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse.end?view=netframework-4.8

Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran 



BS Bert Sirkin June 9, 2020 12:18 PM UTC

I'm not sure this applies to me, as I'm not running the Asp.Net MVC platform- my project is am ASP.NET Webforms project.

I eliminated the Try/Catch, but it still generates an error.


MR Manikandan Ravichandran Syncfusion Team June 10, 2020 02:33 PM UTC

Hi Bert,

Thank you for your update.

This is applicable or both MVC and WebForms applications which are returns the output to client. After removing the try catch statement form the sample, the exception not received by catch block and directly sent to client browse and its working fine in our end.

Please find the modified sample from below link.
https://www.syncfusion.com/downloads/support/forum/154801/ze/SyncfusionDocIoTest2774479913


Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran 


Marked as answer

EG Edes Gomes March 26, 2022 09:45 PM UTC

I'am using the last version of syncfusion export Component. I use Asp.Net WebForms and my frameword is 4.72. I use the following call:

FlatGridLotacao.DataSource = dtLotacao;

FlatGridLotacao.DataBind();


exp.Export(FlatGridLotacao.Model, FlatGridLotacao.DataSource, "Relatório Usuários Por Departamento de Lotação.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime");


System.Threading.ThreadAbortException: 'Thread was being aborted.' is the error that I getting.


   em System.Threading.Thread.AbortInternal()

   em System.Threading.Thread.Abort(Object stateInfo)

   em Syncfusion.XlsIO.Implementation.WorkbookImpl.SaveAs(String fileName, HttpResponse response, ExcelDownloadType downloadType, ExcelHttpContentType contentType)

   em Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, Object dataSource, Boolean multipleExport)




PS Pon Selva Jeganathan Syncfusion Team March 29, 2022 03:33 PM UTC

Hi Edes,


Thanks for contacting syncfusion forum.


We checked your query by preparing sample, but we are unable to reproduce the issue(script error thrown while exporting) at our end.


Please refer to the below attached sample.


After following the above reference, still faced issue please share with us the following details.


  1. Share the complete Grid code example (both client and server)
  2. Please share the product detail version.
  3. Share the issue reproducible sample or reproduce the issue in our shared sample.


The information provided will be helpful to provide you with a response as early as possible. 


Regards,

Pon selva


Attachment: webform_export_fdc4f2c9.zip

Loader.
Up arrow icon