0

I am trying to create a .pdf file on a aspx link button. Below is my code:

    protected void lbtnInvoice_Click(object sender, EventArgs e)
    { 
        List<InvoiceView> invoices = GetInvoices();

        FastReport.Utils.Config.WebMode = true;
        Report rep = new Report();
        var path = @"PathToDataFileToBeUsedByReport\Report.Data";
        rep.Load(path);
        rep.RegisterData(invoices, "Invoice", FastReport.Data.BOConverterFlags.AllowFields, 2);

        if (rep.Report.Prepare())    //Exception Thrown here!
        {
            FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
            pdfExport.ShowProgress = false;
            pdfExport.Subject = "Subject";
            pdfExport.Title = "xxxxxxx";
            pdfExport.Compressed = true;
            pdfExport.AllowPrint = true;
            pdfExport.EmbeddingFonts = true;

            MemoryStream strm = new MemoryStream();
            rep.Report.Export(pdfExport, strm);
            rep.Dispose();
            pdfExport.Dispose();
            strm.Position = 0;

            return File(strm, "application/pdf", "report.pdf");
        }
    }

But the exception Object reference not set to an instance of an object is thrown on rep.Report.Prepare()

Any help is really appreciated.

Edit: I get the same error when I replace rep.Report.Prepare() with rep.Prepare(), in which case I know rep is not null.

Yalda
  • 660
  • 1
  • 13
  • 35
  • My guess is that `rep.Report` is null. Try debugging and find out. – Ant P Apr 23 '14 at 12:04
  • Thanks but it's not a duplicate. I get the error on `rep.Export(blabla)` too, and clearly, `rep` is not null – Yalda Apr 23 '14 at 12:10
  • Before you ask on StackOverflow, you need to *use the debugger* and find out what's null. Until you've done that and shared the results, it is very much a duplicate. – Ant P Apr 23 '14 at 12:33
  • I have used the debugger, but I can't step into FastReport's dll – Yalda Apr 26 '14 at 04:25

0 Answers0