Skip to content

Passing a path to crystal report parameter for Picture objec

bob jason tiamsic

Asked Jul 7, 2015, 1:26 AM EDT1 answer
Share
LinkedInX
Hi. I'm trying to pass an image path to a parameter in Crystal Report where I used this parameter to fill in the picture object in the report.
However when I tried to pass the image path to crystal report parameter using c#, I get this error: String reference not set to an instance of a String.
 
Here is my code:
I referenced:
PowerShell
using CrystalDecisions.Web;
using CrystalDecisions.Reporting;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
 

Java
string qryStr = Request.QueryString["report"].ToString(); //I get the filename based on the querystring of the URL e.g EmployeeNo902706
            ReportDocument rpt = new ReportDocument();
            string rptPath = "../Reports/SampleReportPicture.rpt";
            rpt.Load(Server.MapPath(rptPath));
            CrystalDecisions.CrystalReports.Engine.ReportClass clsPic = new CrystalDecisions.CrystalReports.Engine.ReportClass();
clsPic.SetParameterValue(2, "C:\\inetpub\\wwwroot\\ISMPayroll_Reports\\" + qryStr + ".bmp"); --I GET THE ERROR HERE
Code
                    Page.Response.Clear();
                    Page.Response.Buffer = true;
                    MemoryStream os = (MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    Page.Response.ContentType = "application/pdf";
                    Page.Response.BinaryWrite(os.ToArray());
                    Page.Response.End();

            rpt.Close();
            rpt.Dispose();
 
Can someone help me with this? 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    The error disappeared when I changed the code of passing the parameter to:
     
    Code
    string a = "C:\\inetpub\\wwwroot\\ISMPayroll_Reports\\" + qryStr + ".bmp";
                crParameterDiscreteValue.Value = a;
                crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["PicturePath"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;
    
                crParameterValues.Clear();
                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
     
     
     
    However, the image does not change. Any help? 
    0