|
-
load an image based on a provided filepath in the report at runtime.
Hi
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...
i will paste the coding part
Code:
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
Try
'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
Similar Threads
-
By Scott Kessler in forum Web
Replies: 0
Last Post: 03-21-2001, 05:46 PM
-
By Arty Clark in forum VB Classic
Replies: 2
Last Post: 08-24-2000, 11:24 AM
-
By Garrett Smith in forum Enterprise
Replies: 0
Last Post: 07-31-2000, 04:00 PM
-
By Scott Stanaland in forum VB Classic
Replies: 8
Last Post: 05-31-2000, 12:07 PM
-
By Arty Clark in forum VB Classic
Replies: 0
Last Post: 03-26-2000, 04:21 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks