Dear,
Kindly note that i am trying to print a report using .Print(true) method; but, it gives me NullReferenceException when hosting the application on the server.
When testing it locally, the print dialog box correctly shows up and I am able to print (I am using the version '2013.1.1600.0').
below is the full event viewer log:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 3/24/2015 9:33:50 AM
Event time (UTC): 3/24/2015 7:33:50 AM
Event ID: c0f4f818ab3d41c48ff7eb1241cd1831
Event sequence: 21
Event occurrence: 2
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/3/ROOT/...
Trust level: Full
Application Virtual Path: <Application Pool>
Application Path: C:\inetpub\wwwroot\...
Machine name: <servername>
Process information:
Process ID: 27040
Process name: w3wp.exe
Account name: <Account>
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at Stimulsoft.Base.StiExceptionForm..ctor(Exception exception)
at Stimulsoft.Base.StiExceptionProvider.Show(Exception exception)
at Stimulsoft.Report.Print.StiPrintProvider.Print(StiReport report, Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog)
at btnPrint_Click(Object sender, ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: <RequestURL>
Request path: <RequestPath>
User host address: <IP>
User: <User>
Is authenticated: True
Authentication Type: Negotiate
Thread account name: <Account>
Thread information:
Thread ID: 11
Thread account name:
Is impersonating: False
Stack trace: at Stimulsoft.Base.StiExceptionForm..ctor(Exception exception)
at Stimulsoft.Base.StiExceptionProvider.Show(Exception exception)
at Stimulsoft.Report.Print.StiPrintProvider.Print(StiReport report, Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog, Int32 fromPage, Int32 toPage, Int16 copies, PrinterSettings printerSettings)
at Stimulsoft.Report.StiReport.Print(Boolean showPrintDialog)
at btnPrint_Click(Object sender, ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
Any help would be very appreciated.
Thank you in Advance
Charles
Report.Print() NullReferenceException Error
Re: Report.Print() NullReferenceException Error
Hello,
On the Web you can not print to a printer using report.Print() method.
Please see the following article on our knowledgebase:
http://support.stimulsoft.com/index.php ... a-web-page
Thank you.
On the Web you can not print to a printer using report.Print() method.
Please see the following article on our knowledgebase:
http://support.stimulsoft.com/index.php ... a-web-page
Thank you.
Re: Report.Print() NullReferenceException Error
Thank you for your reply.
I added the StiwebViewer to my aspx page, but it is shown on the page when running the application (I need it when clicking Print button); however, I added the below code when clicking on Print button but nothiing is happening.
I added the report as a dll reference to my project.
Below is the code written on button Print click:
DataTable dttRecords = RetrieveRecords(strEntityAttribute, strAttributeValue);
CustomReport rptCustomReport = new CustomReport();
rptCustomReport.ReportName = "Report (" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-sss") + ")";
rptCustomReport.Image1.Image = Image.FromFile(ConfigurationManager.AppSettings["LogoURL"].ToString());
rptCustomReport.CustomerId = strId;
rptCustomReport.CustomerName = strCustomerName.ToUpper();
rptCustomReport.DataSources[0].DataTable = dttRecords;
//rptCustomReport.Print(true); (This Method was used)
//rptCustomReport.Load("");
rptCustomReport.Render(false);
StiWebViewer1.Report = rptCustomReport;
StiWebViewer1.PrintToDirect();
//StiWebViewer1.PrintToPdf();
//StiWebViewer1.PrintToPopupWindow();
Please advise if there is anything wrong in my above code and my aspx page in order to be able to print the needed report and to show the StiWebViewer only when printing?
Thank You
Charles.
I added the StiwebViewer to my aspx page, but it is shown on the page when running the application (I need it when clicking Print button); however, I added the below code when clicking on Print button but nothiing is happening.
I added the report as a dll reference to my project.
Below is the code written on button Print click:
DataTable dttRecords = RetrieveRecords(strEntityAttribute, strAttributeValue);
CustomReport rptCustomReport = new CustomReport();
rptCustomReport.ReportName = "Report (" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-sss") + ")";
rptCustomReport.Image1.Image = Image.FromFile(ConfigurationManager.AppSettings["LogoURL"].ToString());
rptCustomReport.CustomerId = strId;
rptCustomReport.CustomerName = strCustomerName.ToUpper();
rptCustomReport.DataSources[0].DataTable = dttRecords;
//rptCustomReport.Print(true); (This Method was used)
//rptCustomReport.Load("");
rptCustomReport.Render(false);
StiWebViewer1.Report = rptCustomReport;
StiWebViewer1.PrintToDirect();
//StiWebViewer1.PrintToPdf();
//StiWebViewer1.PrintToPopupWindow();
Please advise if there is anything wrong in my above code and my aspx page in order to be able to print the needed report and to show the StiWebViewer only when printing?
Thank You
Charles.
Re: Report.Print() NullReferenceException Error
Hello, Charles.
You should divide your code on two parts. At first you should create the report in Page Load event:
Then in Click event of Button you should use next code:
Thank you.
You should divide your code on two parts. At first you should create the report in Page Load event:
Code: Select all
if (!Page.IsPostBack) {
DataTable dttRecords = RetrieveRecords(strEntityAttribute, strAttributeValue);
CustomReport rptCustomReport = new CustomReport();
rptCustomReport.ReportName = "Report (" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-sss") + ")";
rptCustomReport.Image1.Image = Image.FromFile(ConfigurationManager.AppSettings["LogoURL"].ToString());
rptCustomReport.CustomerId = strId;
rptCustomReport.CustomerName = strCustomerName.ToUpper();
rptCustomReport.DataSources[0].DataTable = dttRecords;
//rptCustomReport.Print(true); (This Method was used)
//rptCustomReport.Load("");
rptCustomReport.Render(false);
StiWebViewer1.Report = rptCustomReport;
}
Code: Select all
StiWebViewer1.PrintToDirect();
//StiWebViewer1.PrintToPdf();
//StiWebViewer1.PrintToPopupWindow();