Reputation: 165
I do a code in C# to generate reports with Crystal Reports and open in PDF on Browser.
When the user login in the system and go to generate one of the reports the first time, it takes a long time to process...but, after generate first report, the others are generated automatically!
Someone know what do i do ? My code is:
When Click in the button to generate PDF:
ReportDocument Rel = new ReportDocument();
Rel.Load(Server.MapPath("../Reports/Report1.rpt"));
Rel.SetParameterValue("@Id", Id);
Session.Add("Report", Rel);
string _open = "window.open('Report.aspx');";
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), _open, true);
In the page "Report.aspx":
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["Report"] != null)
OpenPDF((ReportDocument)Session["Report"]);
}
}
private void OpenPDF(ReportDocument Rel)
{
MemoryStream stream = (MemoryStream)Rel.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(stream.ToArray());
Response.End();
}
Thanks!
Upvotes: 0
Views: 648
Reputation: 2424
Not sure what your report file contains and if it's processing more pages than what your exporting, but you could preload the runtime for the users so subsequent report renders aren't as noticeable in execution time.
EDIT:
Create a blank report and have it load somewhere, e.g., on Page_Load of a previous page that they go to before generating reports; homepage or subsection. Then just close and dispose of the report afterwards. Also, remove any Crystal Reports assemblies you aren't using from your project references.
Upvotes: 1