Click here to Skip to main content
13,357,363 members (72,345 online)
Click here to Skip to main content
Add your own
alternative version


73 bookmarked
Posted 30 Oct 2007

Image in Crystal Reports

Rate this:
Please Sign up or sign in to vote.
This is sample small project to display image in crystal report
Screenshot - ImgInReport.gif


This article will display the image in crystal report viewrBackground

Using the code

Simply open the source code in 2003.

    try { 
        // here i have define a simple datatable inwhich image will recide 
        DataTable dt = new DataTable(); 
        // object of data row 
        DataRow drow; 
        // add the column in table to store the image of Byte array type 
        dt.Columns.Add("Image", System.Type.GetType("System.Byte[]")); 
        drow = dt.NewRow; 
        // define the filestream object to read the image 
        FileStream fs; 
        // define te binary reader to read the bytes of image 
        BinaryReader br; 
        // check the existance of image 
        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 
        // add row into the datatable 
        // close the binary reader 
        // close the file stream 
        CrystalReport1 rptobj = new CrystalReport1(); 
        // object of crystal report 
        // set the datasource of crystalreport object 
        CrystalReportViewer1.ReportSource = rptobj; 
        //set the report source 
    catch (Exception ex) { 
        // error handling 
        Interaction.MsgBox("Missing 10157.jpg or nophoto.jpg in application folder"); 
// run the application to view image in report 

Remember if you are using c# the paste the above code in button click event

Points of Interest

In this article you will be also able to convert the image into byte array


In this project after clicking the button the action are performed you are free to modify as per your requirement
Feel free for any querrrrrries.

enjoy .net


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

TangoCharli (Anant Tiwari)
Software Developer (Senior) Avenues Technologies Pvt Ltd
India India
MCTS Microsoft Certified Technology Specialist
Computer Engineer

You may also be interested in...

Comments and Discussions

QuestionQuery about your post Pin
Member 1326593018-Jun-17 8:50
memberMember 1326593018-Jun-17 8:50 
Questionhi TangoCharli I have question for your post (Image in Crystal Reports) Pin
Sraj Muneer12-May-17 11:52
memberSraj Muneer12-May-17 11:52 
PraiseThank you Pin
JD.Naik22-Apr-17 4:38
memberJD.Naik22-Apr-17 4:38 
Questionttx file Pin
Member 1057908431-Mar-17 5:30
memberMember 1057908431-Mar-17 5:30 
QuestionIt is possible to choose the location where the image will be added no rpt ? Pin
bydario1-Jun-16 9:09
memberbydario1-Jun-16 9:09 
QuestionAdding image from path specified Pin
Member 1207720221-Oct-15 11:42
memberMember 1207720221-Oct-15 11:42 
Questionview jpg image pdf using crystal report Pin
Member 108569972-Aug-15 18:49
memberMember 108569972-Aug-15 18:49 
QuestionNow working Pin
heemanshu bhalla25-Oct-13 5:17
memberheemanshu bhalla25-Oct-13 5:17 
QuestionNot working Pin
heemanshu bhalla25-Oct-13 1:23
memberheemanshu bhalla25-Oct-13 1:23 
GeneralMy vote of 5 Pin
Member 937103828-Jun-13 1:13
memberMember 937103828-Jun-13 1:13 
GeneralMy vote of 5 Pin
supriya chaladi28-Jan-13 23:12
membersupriya chaladi28-Jan-13 23:12 
GeneralThnk u Pin
kiransolkar24-Dec-12 22:05
memberkiransolkar24-Dec-12 22:05 
QuestionBlob Field Pin
Raghavendra Rao 55815-Nov-12 2:01
memberRaghavendra Rao 55815-Nov-12 2:01 
Questiondatabase expert query Pin
Nikhil S Soni23-Oct-12 1:40
memberNikhil S Soni23-Oct-12 1:40 
AnswerRe: database expert query Pin
kiransolkar24-Dec-12 21:41
memberkiransolkar24-Dec-12 21:41 
GeneralMy vote of 5 Pin
manoj kumar choubey23-Feb-12 20:13
membermanoj kumar choubey23-Feb-12 20:13 
Generalwant image to be shown on special point of Report Pin
edinazem2-May-11 22:34
memberedinazem2-May-11 22:34 
GeneralMy vote of 5 Pin
sohebrapati19-Mar-11 2:31
groupsohebrapati19-Mar-11 2:31 
AnswerSimple Solution - BlobField - How answered Pin
IndomitablePhoenix10-Jan-11 13:02
memberIndomitablePhoenix10-Jan-11 13:02 
Unsure | :~ So a lot of people were wondering how to create the IBlobField in the Crystal Reports Confused | :confused:
Here's a simple solution Shucks | :-\

1. Creat a VARBINARY(MAX)/Image in the database (SQL)
[Image is more recommended as for the size it would hold & as it works for both images & pdf files]
(*)for more details: {}

2. Include the database (using the Database Expert) datasource for the Crystal Report
3. Drag the column onto the Crystal Report & it will automatically become a IBlobField

i.e. the image is converted to Byte() type to be read with the binary reader; hence you store the binary data in the database (the converted image) - this also allows you to store the images in the database instead of image files.
Just make the conversion of the image @ the time of data-entry, then save it (for eg. using a dataAdapter update query) in the database. Now, everytime you view the data in the Crystal report field - it will show the image with no need for run-time conversion.
In case of run-time solution on how to create the Dataset that allows the dragging of the IBlobField OMG | :OMG:
Here's another solution Shucks | :-\
{adapted from the post: Image in Crystal Reports without logon to database popup by Huseyin Altindag which has been posted on 15:34 20 Feb '10}

1.Compile the sample code after making the following addition/change:
Add the following line after to the addition of the dt to the ds:

or ds.WriteXml("mydataset.xml")

(*)for more details:{}

2.After running/executng the code; Go to the path where you set (in this case it's: "Server.MapPath" & look for the file "mydataset.xsd") & edit the name of the dataset or any attribute in it in the xml file then save it.

3.Now "Add a new item" to the project & set the "File path" of the dataset to the xml file in step 2. (this will be save as a dataset - from an XML file)

Now you can use that data set (byte column) & drag it to the crystal report to be used for the conversion @ run-time.

Note: the run-time solution helps reduce the overhead & trouble for the SQL Server in handling images in addition to run-time loading, also it is better to just store the file path of the image/pdf rather than the actual file (the storage would grow exponentially with the addition o records).

Roll eyes | :rolleyes: Hope this helps Smile | :)

modified on Wednesday, January 12, 2011 5:57 PM

Generalpdf too large Pin
yi24-Oct-10 0:44
memberyi24-Oct-10 0:44 
AnswerRe: pdf too large [modified] Pin
IndomitablePhoenix11-Jan-11 8:38
memberIndomitablePhoenix11-Jan-11 8:38 
Generali want image should come from database from msaccess Pin
krunal108915-Sep-10 9:45
memberkrunal108915-Sep-10 9:45 
AnswerRe: i want image should come from database from msaccess Pin
IndomitablePhoenix11-Jan-11 8:55
memberIndomitablePhoenix11-Jan-11 8:55 
GeneralBlob Field Pin
enzo583-Aug-10 20:44
memberenzo583-Aug-10 20:44 
AnswerRe: Blob Field [modified] Pin
IndomitablePhoenix11-Jan-11 8:56
memberIndomitablePhoenix11-Jan-11 8:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 30 Oct 2007
Article Copyright 2007 by TangoCharli (Anant Tiwari)
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid