Search code examples
asp.netc#-4.0crystal-reports

How to dynamically load an image from local drive into crystal report using ASP.Net and C#?


I am having some problem to load picture which is a Logo to the crystal report with its location path:

I am following these below steps:

  1. create a string parameter in the report and name it 'PicPath'
  2. insert an OLE Object (insert menu - OLE Object)
  3. You will get a new window. in that, select the option for 'Create from file' - browse for any picture file () - click on OK step1.JPG
  4. Click on Ok. Place this OLE Object in Report / Page Header according to your design
  5. Right click on the OLE Object -> select 'Format Graphics'
  6. Select 'Picture Tab' step2.JPG
  7. on the Graphic Location click on 'Formula Editor' button. you will get a new formula editing window.
  8. you can see the parameter 'Pic Path' under the 'Report Fields' drag it step3.JPG check for any errors in the formula.

I got these steps from here: http://social.msdn.microsoft.com/Forums/en-US/f869fe3f-ee0f-4ecd-ae7c-9303e0b1f66f/dynamic-image-location-by-using-a-parameter

In the back end I am using this code:

  CrystalDecisions.CrystalReports.Engine.ReportClass clsReport = new CrystalDecisions.CrystalReports.Engine.ReportClass();
 clsReport.SetParameterValue(2, "D:\\mypc\\NEW_Images\\client-logo.bmp");

but every time I am trying to run the project it is giving me error when I click to view the report. And the report is coming with written word "Image" instead of the image.

I am using Asp.net and C sharp to view the report. And Crystal Report XI.


Solution

  • I have solved my problem by adding this handler to my web.config file:

     <add 
        name="ChartImageHandler"
        preCondition="integratedMode"
        verb="GET,HEAD" path="ChartImg.axd"
        type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    

    I got the solution from this page.