ThreadAbortException at ExportToHttpResponse()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dorrit.Riemenschneider@communardo.de

    #1

    ThreadAbortException at ExportToHttpResponse()

    I've developed a sharepint webpart (ASP.NET 2.0 application) with use
    of the CrystalReportVi ewer web control
    (CrystalDecisio ns.Web.CrystalR eportViewer). All works fine except the
    export of the report associated to the CrystalReportVi ewer. I use the
    following source code:

    CrystalDecision s.Web.CrystalRe portViewer crViewer = new
    CrystalDecision s.Web.CrystalRe portViewer();
    CrystalDecision s.Web.CrystalRe portSource crSource = new
    CrystalDecision s.Web.CrystalRe portSource();
    CrystalDecision s.CrystalReport s.Engine.Report Document crSource = null;
    crSource.Report .FileName = reportFilename;
    crDocument = crSource.Report Document;
    this.Controls.A dd(crViewer);
    //...some other stuff
    //...
    //here comes the export
    ExportOptions options = new ExportOptions() ;
    options.ExportF ormatType = ExportFormatTyp e.PortableDocFo rmat;
    crDocument.Expo rtToHttpRespons e(options, this.Page.Respo nse, true,
    "report");

    The export itsself works but a ThreadAbortExce ption is thrown at the
    ExportToHttpRes ponse method and the execution of the page stops.

    I've already found that it is a new feature at ASP.NET 2.0 to abort
    the thread at Response.End or Response.Redire ct (see http://
    support.microso ft.com/kb/312629/EN-US/). But this doesn't really solve
    my problem.

    How can I prevent the ThreadAbortExce ption from being thrown?

    Thanks, Dorrit

  • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

    #2
    RE: ThreadAbortExce ption at ExportToHttpRes ponse()

    This is because, Response.End is called internally in ExportToHttpRes ponse
    method:


    public virtual void ExportToHttpRes ponse(ExportOpt ions options, HttpResponse
    response, bool asAttachment, string attachmentName)
    {
    if ((options.Expor tFormatType == ExportFormatTyp e.HTML40) ||
    (options.Export FormatType == ExportFormatTyp e.HTML32))
    {
    throw new
    NotSupportedExc eption(CREngine Res.GetString(" IDS_ERROR_EXPOR T_TO_RESPONSE_I N_HTML_FORMAT_N OT_SUPPORTED")) ;
    }
    try
    {
    Stream stream1 = this.ExportToSt ream(options);
    response.Clear( );
    SharedUtils.Set ResponseContent (response,
    options.ExportF ormatType, asAttachment, attachmentName) ;

    SharedUtils.Wri teToResponse(re sponse, stream1, true);
    }
    catch (COMException exception1)
    {
    if (!ConvertDotNet ToErom.ThrowDot NetException(ex ception1))
    {
    throw;
    }
    }
    }

    public static void WriteToResponse (HttpResponse response, Stream
    inputStream, bool exclusive)
    {
    if (inputStream != null)
    {
    int num1;
    Stream stream1 = response.Output Stream;
    byte[] buffer1 = new byte[0x1000];
    while ((num1 = inputStream.Rea d(buffer1, 0, 0x1000)) 0)
    {
    stream1.Write(b uffer1, 0, num1);
    }
    stream1.Flush() ;
    if (exclusive)
    {
    response.End();
    }
    }
    }

    Therefore, when you call ExportToHttpRes ponse wrap it with try catch block:

    try
    {
    ExportToHttpRes ponse(...);
    }
    catch (System.Threadi ng.ThreadAbortE xception)
    {

    }

    and You're done.
    --
    Milosz


    "dorrit.Riemens chneider@commun ardo.de" wrote:
    I've developed a sharepint webpart (ASP.NET 2.0 application) with use
    of the CrystalReportVi ewer web control
    (CrystalDecisio ns.Web.CrystalR eportViewer). All works fine except the
    export of the report associated to the CrystalReportVi ewer. I use the
    following source code:
    >
    CrystalDecision s.Web.CrystalRe portViewer crViewer = new
    CrystalDecision s.Web.CrystalRe portViewer();
    CrystalDecision s.Web.CrystalRe portSource crSource = new
    CrystalDecision s.Web.CrystalRe portSource();
    CrystalDecision s.CrystalReport s.Engine.Report Document crSource = null;
    crSource.Report .FileName = reportFilename;
    crDocument = crSource.Report Document;
    this.Controls.A dd(crViewer);
    //...some other stuff
    //...
    //here comes the export
    ExportOptions options = new ExportOptions() ;
    options.ExportF ormatType = ExportFormatTyp e.PortableDocFo rmat;
    crDocument.Expo rtToHttpRespons e(options, this.Page.Respo nse, true,
    "report");
    >
    The export itsself works but a ThreadAbortExce ption is thrown at the
    ExportToHttpRes ponse method and the execution of the page stops.
    >
    I've already found that it is a new feature at ASP.NET 2.0 to abort
    the thread at Response.End or Response.Redire ct (see http://
    support.microso ft.com/kb/312629/EN-US/). But this doesn't really solve
    my problem.
    >
    How can I prevent the ThreadAbortExce ption from being thrown?
    >
    Thanks, Dorrit
    >
    >

    Comment

    • Dorrit

      #3
      Re: ThreadAbortExce ption at ExportToHttpRes ponse()

      I've already wrapped the call in a try catch block but my problem is
      this: the thread is actually aborted after the call of
      ExportToHttpRes ponse and no events (button_click etc.) are fired. I
      have to manually reload the page (F5 in browser) in order to "reawake"
      the page.

      If there is no possibility to prevoid the ThreadAbortExce ption from
      beeing thrown:

      1. How can I do the "reawake" of the page programmaticall y?

      2. Even better: Is there a possibility to call ExportToHttpRes ponse
      not with "this.Page.Resp onse" but rather with another responce object
      (a clon or so ... which may be aborted...)?

      Thanks, Dorrit

      Comment

      • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

        #4
        RE: ThreadAbortExce ption at ExportToHttpRes ponse()

        Hi there again,

        I don't actually think so. Could you just use iframe with a page that takes
        reposibility of this task?
        --
        Milosz


        "dorrit.Riemens chneider@commun ardo.de" wrote:
        I've developed a sharepint webpart (ASP.NET 2.0 application) with use
        of the CrystalReportVi ewer web control
        (CrystalDecisio ns.Web.CrystalR eportViewer). All works fine except the
        export of the report associated to the CrystalReportVi ewer. I use the
        following source code:
        >
        CrystalDecision s.Web.CrystalRe portViewer crViewer = new
        CrystalDecision s.Web.CrystalRe portViewer();
        CrystalDecision s.Web.CrystalRe portSource crSource = new
        CrystalDecision s.Web.CrystalRe portSource();
        CrystalDecision s.CrystalReport s.Engine.Report Document crSource = null;
        crSource.Report .FileName = reportFilename;
        crDocument = crSource.Report Document;
        this.Controls.A dd(crViewer);
        //...some other stuff
        //...
        //here comes the export
        ExportOptions options = new ExportOptions() ;
        options.ExportF ormatType = ExportFormatTyp e.PortableDocFo rmat;
        crDocument.Expo rtToHttpRespons e(options, this.Page.Respo nse, true,
        "report");
        >
        The export itsself works but a ThreadAbortExce ption is thrown at the
        ExportToHttpRes ponse method and the execution of the page stops.
        >
        I've already found that it is a new feature at ASP.NET 2.0 to abort
        the thread at Response.End or Response.Redire ct (see http://
        support.microso ft.com/kb/312629/EN-US/). But this doesn't really solve
        my problem.
        >
        How can I prevent the ThreadAbortExce ption from being thrown?
        >
        Thanks, Dorrit
        >
        >

        Comment

        • Dorrit

          #5
          Re: ThreadAbortExce ption at ExportToHttpRes ponse()

          Hi again,

          I have implemented the following workaround: I export the report not
          to http resonse (this kills the thread and throws the exception - no
          chance) but to disk. I then open a new browser window with java script
          and navigate to an aspx page. I give the filename of the exported file
          and the content type corresponding to the export format to the page.
          In the Load event of the aspx page I load the exported file into the
          page. In the Unload event I delete the exported file from disk.

          This is not a very nice but working solution.

          Dorrit

          Comment

          • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

            #6
            Re: ThreadAbortExce ption at ExportToHttpRes ponse()

            Hi Dorrit gaian,

            Good to hear you solved the problem. In case you have any issues in future,
            use Reflector (http://www.aisto.com/roeder/dotnet/) to investigate the code
            yourself.

            Regards
            --
            Milosz


            "Dorrit" wrote:
            Hi again,
            >
            I have implemented the following workaround: I export the report not
            to http resonse (this kills the thread and throws the exception - no
            chance) but to disk. I then open a new browser window with java script
            and navigate to an aspx page. I give the filename of the exported file
            and the content type corresponding to the export format to the page.
            In the Load event of the aspx page I load the exported file into the
            page. In the Unload event I delete the exported file from disk.
            >
            This is not a very nice but working solution.
            >
            Dorrit
            >
            >

            Comment

            Working...