Skip to Content
0
Former Member
Dec 06, 2009 at 02:56 PM

Problem loading report from asp .net

17 Views

Hi:

I have the following problem: after deploying my web site, when users want to print a report sometimes the report does not come up and sometimes it does, after putting some return lines in the code I have realized that this is the line where the problem occurs:

rpt.Load(Server.MapPath(path));

this is the full code I am using:

public CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = 
new CrystalDecisions.CrystalReports.Engine.ReportDocument();

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
       
        string path = "test.rpt";

        rpt.Load(Server.MapPath(path));
        System.IO.MemoryStream oStream;
        oStream = (System.IO.MemoryStream)
(rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
        
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("Content-Length", oStream.Length.ToString());
        Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf");
        Response.ContentType = "application/pdf";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.BinaryWrite(oStream.ToArray());
        Response.End();
    }


    protected void Page_Unload(object sender, EventArgs e)
    {
        rpt.Close();
        rpt.Dispose();
        GC.Collect();
    }

By the way I am using visual studio 2008 and framework 3.5

I have set PrintJobLimit registry key to -1 in both InProcServer and Server keys, but the problem seems to persist, every time I have to restart IIS after doing that the report comes up, at the beginning I though I was doing something wrong at design time, but after putting a blank report with only some lines of text it seems that there is a configuration or settings problem somewhere (perhaps coding error).

Thanks in advance.

Edited by: gabrieldcr2 on Dec 6, 2009 4:01 PM

Edited by: gabrieldcr2 on Dec 6, 2009 4:02 PM