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.