Click here to Skip to main content
15,176,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am passing images from my local disk to crystal reports using code. I have completed passing one image from my local drive to crystal reports, but the issue is I want to pass many images from the same drive. I am using the code below for passing the images:

' object of data row
     Dim drow As DataRow
     ' 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
     Dim fs As FileStream
     ' define te binary reader to read the bytes of image
     Dim br As BinaryReader
     ' check the existance of image
     If File.Exists(AppDomain.CurrentDomain.BaseDirectory & "10157.Jpg") Then
         ' 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 & "FLYWELL.jpg", FileMode.Open)
     End If
     ' initialise the binary reader from file streamobject
     br = New BinaryReader(fs)
     ' define the byte array of filelength
     Dim imgbyte(fs.Length) As Byte
     ' 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
     Dim rptobj As New CrystalReport1    ' object of crystal report
     CrystalReportViewer1.ReportSource = rptobj  'set the report source
Updated 29-Jun-21 17:27pm
Manfred Rudolf Bihy 30-Mar-11 8:03am
Edit: Added code tags, spelling and grammar, sensible title added
Kschuler 30-Mar-11 11:48am
You asked this exact same question 2 days ago:
What work have you done on it since?

1 solution

sameertm 30-Mar-11 9:20am
Dear Sandeep in my question i have mentioned some coding that coding itself i can pass images, but the problem is i can pass only one image i want to pass many images
Sandeep Mewara 30-Mar-11 9:31am
So, add them to a datatable row-wise ans then refer the datatable to crystal report.
sameertm 30-Mar-11 9:41am
can u tell me how to add data table
Sandeep Mewara 30-Mar-11 9:46am
You can add datatable as a datasource to reports. Right?
sameertm 30-Mar-11 9:48am
can u give some sample coding for create datatable
Kschuler 30-Mar-11 12:26pm
You already ARE creating a datatable in your code and you are setting it as the datasource with this statement:


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900