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 viewer

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

'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 = _
dsImgRpt.Image.NewImageRow

'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
dsImgRpt.Image.Rows.Add(dr)

'Use the dataset as datasource for the report
m_imagereport.SetDataSource(dsImgRpt)

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

d h o l

02-20-2008, 05:30 AM

DaveT

Re: Load an image based on a provided filepath in the report at runtime.

Hello,

Below is the converted code in C# and you shall see the comments along with the code which explains the function the code would be performing:

try {
//Create a new instance of the dataset
dsImageReport dsImgRpt = new dsImageReport();
//Create a new instance of the report
rptImage m_imagereport = new rptImage();
//Create a new row in the dataset
dsImageReport.ImageRow dr = dsImgRpt.Image.NewImageRow;
//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
dsImgRpt.Image.Rows.Add(dr);
//Use the dataset as datasource for the report
m_imagereport.SetDataSource(dsImgRpt);
//Show the report in the reportviewer
this.crystalReportViewer1.ReportSource = m_imagereport;
}
catch (Exception ex) {
MessageBox.Show("Something went wrong: " + ex.Message);
}
}
}