469,950 Members | 2,348 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

load an image based on a provided filepath in the report at runtim


I have to program in C# such that I have to add a button to the form , and
create a crystal report, by getting source
from the xml schema file(.xsd file) with two fields namely name,image.....
name is string datatype and image is of
datatype base64Binary. Now i have to add a crystal report viewer to the form
and whenthe program is run, we
should be able to load any image ,ie, by clicking the button add any image
from the disk and that image should be displayed
in the report in image column......
so wht i have to do is
-create a dataset that supports images
-create a report that support this dataset
-load data in the dataset
-use the dataset as datasource for the report and show the report in the

Then i found a code in Vb...
please change for me in c# and explain how to do...

i will paste the coding part
Private Sub btnLoadImage_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnLoadImage.Click

Dim ofdImage As New OpenFileDialog

If ofdImage.ShowDialog = DialogResult.OK Then


'Create a new instance of the dataset
Dim dsImgRpt As New dsImageReport

'Create a new instance of the report
Dim m_imagereport As New rptImage

'Create a new row in the dataset
Dim dr As dsImageReport.ImageRow = _

'Set the various elements of the row
dr.Name = ofdImage.FileName
'fill this field with a byte array
dr.Photo = GetImageData(ofdImage.FileName)

'Add the new row to the dataset

'Use the dataset as datasource for the report

'Show the report in the reportviewer
Me.crystalReportViewer1.ReportSource = m_imagereport

Catch ex As Exception

MessageBox.Show("Something went wrong: " & ex.Message)

End Try

End If

End Sub

Private Function GetImageData(ByVal fileName As String) As Byte()

'Method to load an image from disk and return it as a bytestream
Dim fs As System.IO.FileStream = _
New System.IO.FileStream(fileName, _
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs)
Return (br.ReadBytes(Convert.ToInt32(br.BaseStream.Length )))

End Function
please help me to do this..

Nov 17 '05 #1
0 1507

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by haddock | last post: by
4 posts views Thread by Shumit Rehman | last post: by
3 posts views Thread by Gary B | last post: by
6 posts views Thread by comp.lang.php | last post: by
3 posts views Thread by den 2005 | last post: by
1 post views Thread by ckarbass | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.