Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here i want to display image on crystal report whose path is stored in web.config file
here i have addedd image path in web.config file as like bellow code

What I have tried:

XML
<appSettings>    
     <add key="logo" value="Images/1.jpg" />   
 </appSettings>


and i have tried some c# code ,which is as follows

C#
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 this is not rendering anything,so can any one help me to solve this issue??
Posted
Updated 22-May-16 20:41pm

1 solution

i resolved this as per below process
add image path to web.config file as like
C#
<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

C#
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 it and your Done
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900