Click here to Skip to main content
6,630,901 members and growing! (17,300 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Image in Crystal Reports

By TangoCharli (Anant Tiwari)

This is sample small project to display image in crystal report
C#, VB, Windows, .NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0VS.NET2003, VS2005, Dev, Design
Posted:30 Oct 2007
Views:42,944
Bookmarked:31 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 2.61 Rating: 2.89 out of 5
2 votes, 25.0%
1

2
1 vote, 12.5%
3
1 vote, 12.5%
4
4 votes, 50.0%
5
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)


Member
MCTS Microsoft Certified Technology Specialist
C-Dac
Computer Engineer
Occupation: Software Developer (Senior)
Location: India India

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
Generalblob field object [modified] Pinmemberapol524 p15:22 4 Nov '09  
GeneralGood job! PinmemberNguyennamhs22:48 27 Oct '09  
Generalhi Pinmembershrimast22:38 25 Sep '09  
GeneralDatabase Login Error PinmemberMATTXtwo20:19 26 May '09  
GeneralHow to display image in crystal report VS 2005 Pinmemberkiddsx4u10:42 17 Apr '09  
GeneralAccess denied exception Pinmembernihad aliyev2:36 26 Nov '08  
GeneralGreat !!! Pinmemberlcsistemas14:29 8 Oct '08  
Generalhow to make Image object on crystal report Pinmembernaveed883:08 12 Sep '08  
AnswerRe: how to make Image object on crystal report Pinmemberhugoflores6:13 9 Apr '09  
GeneralImage in Crystal Reports Pinmemberdkinjal_2820:18 23 Jul '08  
GeneralGreat PinmemberMember 45824256:15 11 Mar '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Oct 2007
Editor:
Copyright 2007 by TangoCharli (Anant Tiwari)
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project