Click here to Skip to main content
Click here to Skip to main content

Image in Crystal Reports

By , 29 Oct 2007
 
Screenshot - ImgInReport.gif

Introduction

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 
        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 
        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

History

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

License

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
Member
MCTS Microsoft Certified Technology Specialist
C-DAC
Computer Engineer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Blob FieldmemberMember 607717516 Dec '09 - 2:49 
did u get the solutions for this?
GeneralRe: Blob FieldmemberMember 448541928 Dec '09 - 18:35 
Is there anhyone to solve my problem .its urgent.i have to complete my project with in a week.my rest of all project have completed.i have only problem with dis blob field
AnswerRe: Blob Field - AnsweredmemberIndomitablePhoenix11 Jan '11 - 8:06 
This might be too late but for the solution Dead | X| --- kindly read my latest post (Titled: Simple Solution - BlobField - How answered) on how to set the BlobField above Blush | :O
Generalblob field object [modified]memberapol524 p4 Nov '09 - 14:22 
where can i get the blob field object? i am using vs net 2005
 
modified on Wednesday, November 4, 2009 10:30 PM

AnswerRe: blob field object - AnsweredmemberIndomitablePhoenix11 Jan '11 - 8:09 
kindly read my latest post (Titled: Simple Solution - BlobField - How answered) on how to set the BlobField above - I was using VS2005 as well
GeneralGood job!memberNguyennamhs27 Oct '09 - 21:48 
Thank u for this article!
Generalhimembershrimast25 Sep '09 - 21:38 
This is great and awsome. This solves my problem Smile | :)
GeneralDatabase Login ErrormemberMATTXtwo26 May '09 - 19:19 
your code is good but the lack is that u have to provide the database definition file .ttx
so could u please alert me for this file..
mattrr85@yahoo.com
AnswerRe: Database Login Error - possible solutionmemberIndomitablePhoenix11 Jan '11 - 8:12 
for the database definition, kindly read my latest post above(Titled: Simple Solution - BlobField - How answered) on how to set the DB definition in order to create the BlobField - you won't need the .ttx file Big Grin | :-D
 
Also refer to the post: Image in Crystal Reports without logon to database popup by Huseyin Altindag which has been posted on 15:34 20 Feb '10
QuestionHow to display image in crystal report VS 2005memberkiddsx4u17 Apr '09 - 9:42 
Hi,
I tried the code but it didnt work. I keep getting error message "Missing 10157.jpg or nophoto.jpg in application folder"
Also I notice the database type used for the datasource of the crystal report was field definition file type.
 
How can I create field definition file type
 
Please Help
 
Thanks

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

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