Skip to content

Display image on crystal report using web.config file

Madhav

Asked May 22, 2016, 8:33 PM EDT1 answer
Share
LinkedInX
here i want to display image on crystal report using web.config file in which i am storing image path ,from folder in which i have images in solution
 
here i added image path in web.config file within appsetting section like bellow
 
<appSettings>
<add key="logo" value="Images/1.jpg" />
</appSettings>
 
 and i have tried code as bellow in c#
 
 
 
Java
 CrystalReportViewer1.Visible = true;
            string imagePath = ConfigurationManager.AppSettings["logo"];
            string physicalPath = Server.MapPath(imagePath);
            ReportDocument rd = new ReportDocument();
            CrystalReportViewer1.RefreshReport();
            ParameterFields myParams = new ParameterFields();
            ParameterField myParam = new ParameterField();
            ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();
            myParam.ParameterFieldName = "logo";
            myDiscreteValue.Value = physicalPath;
            myParam.CurrentValues.Add(myDiscreteValue);
            myParams.Add(myParam);
            CrystalReportViewer1.ParameterFieldInfo = myParams;
            rd.Load(Server.MapPath("CrystalReport2.rpt"));
            CrystalReportViewer1.ReportSource = rd;
            CrystalReportViewer1.DataBind();
 
 but the crystal report viewer doesn't rendering any thing,can any one help me regarding this issue

1 Answer

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

  • 0
    i resolved this as per below process
    add image path to web.config file as like
    <appSettings>
    <add key="logo" value="Images/1.jpg" />
    </appSettings>
    after adding image path into web.config file ,include crystal report into your solution and in that crystal report add parameter field ,the filed name will be the same as like the key from web.config file,here i have parameter field as "logo"
    fetch image into c# code onto the page to which you are binding report viewer as like bellow code
    Java
     protected void Page_Load(object sender, EventArgs e)
            {
                string imagePath = ConfigurationManager.AppSettings["logo"].ToString();
                string physicalPath = Server.MapPath(imagePath);
    
                ParameterFields myParams = new ParameterFields();
                ParameterField myParam = new ParameterField();
                ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();
    
                myParam.ParameterFieldName = "logo";
                myDiscreteValue.Value = physicalPath;
                myParam.CurrentValues.Add(myDiscreteValue);
    
                myParams.Add(myParam);
                CrystalReportViewer1.ParameterFieldInfo = myParams;
                ReportDocument rd = new ReportDocument();
                rd.Load(Server.MapPath("CrystalReport2.rpt"));
                CrystalReportViewer1.ReportSource = rd;
    
            }
    and after this go to crystal report and insert one default picture on it,after that just right click on that, goto the format object,select picture tab,click on graphics location and select the parameter fields which you have created and after that save close n run it.your Done
    0