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:
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

  • edited 7:57AM
    Hello,
    wrote:
    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?

    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.
    wrote:
    For point (2), in an ASP.NET application, exactly where should one set "FastReport.Utils.Config.WebMode = true;"?

    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.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.