ASP.NET usage questions
Hi,
I am thinking of using FastReport.net in an ASP.NET environment.
One of the requirements, is streaming the FR report PDF (without WebReport), as discussed in message:
http://www.fast-report.com/en/forum/index....1&hl=format
In that message, AlexTZ wrote:
"1. It should, as long as one Report component is used to build/export one report.
2, The only thing you need to do is to set Config.WebMode property to true."
I have all this working well with the Demo FR.NET (see sample below), but please could you clarify/expand the first (1) statement made above?
For point (2), in an ASP.NET application, exactly where should one set "FastReport.Utils.Config.WebMode = true;"?
Kind Regards,
Keith Blows
Sample code:
I am thinking of using FastReport.net in an ASP.NET environment.
One of the requirements, is streaming the FR report PDF (without WebReport), as discussed in message:
http://www.fast-report.com/en/forum/index....1&hl=format
In that message, AlexTZ wrote:
"1. It should, as long as one Report component is used to build/export one report.
2, The only thing you need to do is to set Config.WebMode property to true."
I have all this working well with the Demo FR.NET (see sample below), but please could you clarify/expand the first (1) statement made above?
For point (2), in an ASP.NET application, exactly where should one set "FastReport.Utils.Config.WebMode = true;"?
Kind Regards,
Keith Blows
Sample code:
protected void Page_Load(object sender, EventArgs e)
{
        // No temp files
        FastReport.Utils.Config.WebMode = true;
       Â
        // Set PDF export props
        FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
        pdfExport.ShowProgress = false;
        pdfExport.Subject = "Subject";
        pdfExport.Title = "Title";
        pdfExport.Compressed = true;
        pdfExport.AllowPrint = true;
        pdfExport.Author = "Me";
        pdfExport.Creator = "Me";
        pdfExport.EmbeddingFonts = false;
        pdfExport.Producer = "Me";
        pdfExport.Keywords = "Keywords";
       Â
        string sqlConn ="User ID=user;Password=password;Data Source=127.0.0.1;Initial Catalog=Data";
        string sqlSelect = "SELECT * FROM [SomeTable];";
        // Load our report
        Report report = new Report();
        report.Load(@"D:\temp\ft.net\WebApplication2\App_Data\Test1.frx");
       Â
        // Create and register our custom data       Â
        DataTable ds = new DataTable();
        using (SqlConnection conn = new SqlConnection(sqlConn))
        {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sqlSelect, conn))
                {
                        using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
                        {
                                adapt.Fill(ds);
                        }
                }
        }
        report.RegisterData(ds, "Data");
        report.Prepare();
        ds.Dispose();
        // Export report to PDF stream
        MemoryStream strm = new MemoryStream();
        report.Export(pdfExport, strm);
        report.Dispose();
        pdfExport.Dispose();
        // Stream the PDF back to the client as an attachment
        Response.ClearContent();
        Response.ClearHeaders();
        Response.Buffer = true;
        Response.ContentType = "Application/PDF";
        Response.AddHeader("Content-Disposition", "attachment;filename=Test.pdf");
        strm.Position = 0;
        strm.WriteTo(Response.OutputStream);
        strm.Dispose();
        Response.End();           Â
}
Comments
I meant the following: you can't use one global Report object to prepare several reports. Your example is absolutely correct: you create a Report instance, prepare a report, and dispose it, so one thread uses one Report instance.
You need to execute this code before the very first usage of Report component. For example, in the Page.Load event handler of your main asp page.