ASP.NET - how to place image in crystall report from local project image folder

Asked By mani on 23-Dec-11 07:29 AM
hi..i have image and need to insert in crystal report from my project image folder..please any help??
Jitendra Faye replied to mani on 23-Dec-11 07:33 AM

Using Picture Object of Crystal Report

Using the Dynamic Graphic Location of picture OLE object of crystal report, we can change picture dynamically at run-time.

1. Create a parameter field in the report with string data type.

2 In the report Add a picture OLE object. inside report right click->Insert->OLE object- >select Bitmap Image


3 Right click the OLE picture object and select Format Object- >select Picture tab ->Graphic location -> inside it drag the parameter field.


in the front end just pass the Image URL to the report


ParameterDiscreteValue crParameterimgLocation;


string img_url = @"\\images/newImages/nevadadot.JPG";

img_url = Server.MapPath(img_url);

crParameterField = crParameterFields["imgLocation"];

crParameterValues = crParameterField.CurrentValues;

this.crParameterimgLocation = new ParameterDiscreteValue();

this.crParameterimgLocation.Value = img_url;

 

//Add current value for the parameter field

crParameterValues.Add(crParameterimgLocation);

 

Note: while passing the Image URL do not put put single quotes.


Follow this link also-

http://natrajt.blogspot.com/2008/06/dynamic-images-at-runtime-in-crystal.html

mani replied to Jitendra Faye on 23-Dec-11 07:44 AM
hi i dont want to do it dynamically..just i need to place an image that all??
dipa ahuja replied to mani on 23-Dec-11 10:08 AM
void LoadImage()
  {
    try
    {
  
    DataTable dt = new DataTable();
  
    DataRow drow;
  
    dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
    drow = dt.NewRow();
  
 
    FileStream fs;
    
    BinaryReader br;
    
    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg"))
    {
      // open image in file stream 
 
      fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg"FileMode.Open);
    }
    else
    {
      // if phot does not exist show the nophoto.jpg file 
 
      fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg"FileMode.Open);
    }
    // initialise the binary reader from file streamobject 
 
    br = new BinaryReader(fs);
    // define the byte array of filelength 
 
    byte[] imgbyte = new byte[fs.Length + 1];
    // read the bytes from the binary reader 
 
    imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
    drow[0] = imgbyte;
    // add the image in bytearray 
 
    dt.Rows.Add(drow);
    // add row into the datatable 
 
    br.Close();
    // close the binary reader 
 
    fs.Close();
    // close the file stream 
 
    CrystalReport1 rptobj = new CrystalReport1();
    // object of crystal report 
 
    rptobj.SetDataSource(dt);
    // set the datasource of crystalreport object 
 
    CrystalReportViewer1.ReportSource = rptobj;
    //set the report source 
 
    }
    catch (Exception ex)
    {
    // error handling 
 
    
    }
  }
Anoop S replied to mani on 24-Dec-11 01:17 AM
One solution would be to embed the images as described in http://msdn.microsoft.com/en-us/library/dd239319.aspx  and the tie the visibility property to an expression.

To embed an image in a report

  1. In report design view, on the Insert tab, click Image.

  2. On the design surface, click and then drag a box to the desired size of the image.

  3. In the General page of the Image Properties dialog box, type a name in the Name text box or accept the default.

  4. (Optional) In the ToolTip text box, type the text that you want to appear when the user hovers over the image in the rendered report.

  5. In Select the image source, select Embedded.

  6. Click the Import button next to the Use this image text box

  7. In Files of type, select the image file type, navigate to the file, and then click Open.

  8. In the Image Properties dialog box, click OK.

    The image is displayed in the box you drew on the design surface, and the file is displayed under the Images folder in the Report Data pane.


Also, see the http://social.msdn.microsoft.com/forums/en-us/sqlreportingservices/thread/3CF1FA9C-20FB-41BF-83A8-F8B7A2B477C1 thread in the MSDN forums. People discuss a number of ways to address this there.