.NET - Streaming PDF from RPT file painfully slow

975 Views Asked by At

I'm using C# (.NET 4) to generate and return a PDF from a Crystal RPT file that's part of my app. It works intermittently, but is painfully slow to generate the PDF (sometimes it doesn't complete at all). Any advice on the code below that might point me in the right direction?

// POST: /API/GetReport
[HttpPost]
public ActionResult GetReport()
{
    BoolResponse response = new BoolResponse { };
    string evalID = Request["evalID"] ?? "";
    if (evalID != "" && UserCanViewEval(evalID)) {
        ReportClass rptH = new ReportClass();
        try
        {

            ParameterField paramField = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
            ParameterValues paramValues = new ParameterValues();

            rptH.FileName = Server.MapPath("~/Content/Reports/Eval.rpt");
            rptH.Load();
            rptH.SetParameterValue("EvalID", evalID);

            Stream stream = rptH.ExportToStream(ExportFormatType.PortableDocFormat);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            return new FileStreamResult(stream, "application/pdf");
        }
        catch (Exception e)
        {
            response.errors = e.Message;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        finally {
            rptH.Close();
            rptH.Dispose();
        }
    }
    else {
        return View();
    }
}
1

There are 1 best solutions below

0
On

Looks like I need to have a talk with our report writer. We isolated the cause of the slowness to either the RPT file itself, or the queries in it. I had him run the RPT file directly from his development environment (outside of my .NET app entirely) and it performed the same.

I'm guessing that the queries put together with the GUI in Crystal (by the report writer) aren't terribly efficient, since the rest of my application is lightning fast.