Victor Charles
asked on
Help with viewing images in an MSReport using a Dataset using VB.NET
Hi,
I'm using the code below to view images whose file names are in my xml file and the images are listed in my application's folder, but I'm unable to view the images. How do I solve this issue?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds = New DataSet()
ds.ReadXml(Application.Sta rtupPath + "\linkSearch.xml")
ds.WriteXmlSchema(Applicat ion.Startu pPath + "\linkSearch.xsd")
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli cation.Sta rtupPath + "\LinkSearch.xml", IO.FileMode.Open)
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin kBEL)
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl es(0), Nothing, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
End Sub
Thanks,
Victor
I'm using the code below to view images whose file names are in my xml file and the images are listed in my application's folder, but I'm unable to view the images. How do I solve this issue?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds = New DataSet()
ds.ReadXml(Application.Sta
ds.WriteXmlSchema(Applicat
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl
FilteredDT = DV.ToTable
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
End Sub
Thanks,
Victor
I dont see any code related to image or path...
ASKER
The image is connected to the image field in the rdlc file.
but it is not an image! it is just path to the image...
so I believe you need to set the path/src of image correctly
if path in db is "image1.jpg", and images are stored in "pictures" folder on your server,
maybe you should set the src of image as "http://domain_or_server/pictures/image1.jpg"
so I believe you need to set the path/src of image correctly
if path in db is "image1.jpg", and images are stored in "pictures" folder on your server,
maybe you should set the src of image as "http://domain_or_server/pictures/image1.jpg"
ASKER
I can't hard code tne image names because as I move to each revord I need to see whatever image is in the xml file.
ASKER
This is a windows apication, need to set path to application's folder without hard coding name of the images.
Thanks.
Thanks.
ok then you need to write some code and say
image.path = app.path + ds["imgPath"]
or loop all records in FilteredDT and change path to app.path + ds["imgPath"] before binding to report...
or something like that... I dont think db has full path to file...
image.path = app.path + ds["imgPath"]
or loop all records in FilteredDT and change path to app.path + ds["imgPath"] before binding to report...
or something like that... I dont think db has full path to file...
ASKER
Image.path? How do you declare image before using it in the code?
after this line
FilteredDT = DV.ToTable
you can change the values
for each row in FilteredDT.rows row.imgPath=app.path & row.imgPath
then bind it to report...
FilteredDT = DV.ToTable
you can change the values
for each row in FilteredDT.rows row.imgPath=app.path & row.imgPath
then bind it to report...
ASKER
Thanks, I will try it when I get home. Shouldn't the code include the "Image" field which contains the images' names?
ASKER
I tried your suggestion as shown in code below but getting error message:
An unhandled exception of type 'System.MissingMemberExcep tion' occurred in Microsoft.VisualBasic.dll
Additional information: Public member 'imgPath' on type 'DataRow' not found.
On line: row.imgPath=app.path & row.imgPath
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl es(0), Nothing, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
For each row in FilteredDT.rows
row.imgPath=app.path & row.imgPath
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
Next
An unhandled exception of type 'System.MissingMemberExcep
Additional information: Public member 'imgPath' on type 'DataRow' not found.
On line: row.imgPath=app.path & row.imgPath
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl
FilteredDT = DV.ToTable
For each row in FilteredDT.rows
row.imgPath=app.path & row.imgPath
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
Next
I gave you pseudo code, not exact code!
path of app can be retrieved like this
then for each row change the value before binding
and replace imgPath with your column name...
by the way,
where are your images
how are they stored in db
what column stores those values?
path of app can be retrieved like this
dim path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
ordim path As String = Application.StartupPath()
ordim path As String = Application.ExecutablePath()
then for each row change the value before binding
For each row in FilteredDT.rows
row("imgPath").value=path & row("imgPath").value
and replace imgPath with your column name...
by the way,
where are your images
how are they stored in db
what column stores those values?
ASKER
The images are in my application folder in an image subfolder. The image names are in my xml file (Image data element) which was converted to .xsd to include in the project. I will try your code and get back to you.
Thanks.
Thanks.
so, this should work
dim path As String = Application.ExecutablePath()
For each row in FilteredDT.rows
row("Image").value=path & "image\" & row("Image").value
ASKER
Hi,
Unfortunately it did not work. I received error message:
An unhandled exception of type 'System.MissingMemberExcep tion' occurred in Microsoft.VisualBasic.dll
Additional information: Public member 'value' on type 'String' not found.
On line:
row("Image").value = path & "Image\" & row("Image").value
code:
Dim ds = New DataSet()
ds.ReadXml(Application.Sta rtupPath + "\linkSearch.xml")
ds.WriteXmlSchema(Applicat ion.Startu pPath + "\linkSearch.xsd")
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli cation.Sta rtupPath + "\LinkSearch.xml", IO.FileMode.Open)
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin kBEL)
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl es(0), Nothing, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
MsgBox(FilteredDT.Rows.Cou nt)
Dim path As String = Application.ExecutablePath ()
For Each row In FilteredDT.Rows
row("Image").value = path & "Image\" & row("Image").value
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
Next
Unfortunately it did not work. I received error message:
An unhandled exception of type 'System.MissingMemberExcep
Additional information: Public member 'value' on type 'String' not found.
On line:
row("Image").value = path & "Image\" & row("Image").value
code:
Dim ds = New DataSet()
ds.ReadXml(Application.Sta
ds.WriteXmlSchema(Applicat
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl
FilteredDT = DV.ToTable
MsgBox(FilteredDT.Rows.Cou
Dim path As String = Application.ExecutablePath
For Each row In FilteredDT.Rows
row("Image").value = path & "Image\" & row("Image").value
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
Next
then dont use value!
row("Image").value = path & "Image\" & row("Image").value
>>>
row("Image") = path & "Image\" & row("Image")
row("Image").value = path & "Image\" & row("Image").value
>>>
row("Image") = path & "Image\" & row("Image")
ASKER
Hi,
Below is the code and xml file containing the images for your information, hopefully you can duplicate the project from your end and test it with an image file. I am not able to upload the load the project.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshRe port()
End Sub
Private Sub ReportViewer1_Load(sender As Object, e As EventArgs)
End Sub
Public fslinkBEL As System.IO.FileStream
Public dtsetlinkBEL As New DataSet
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds = New DataSet()
ds.ReadXml(Application.Sta rtupPath + "\linkSearch.xml")
ds.WriteXmlSchema(Applicat ion.Startu pPath + "\linkSearch.xsd")
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli cation.Sta rtupPath + "\LinkSearch.xml", IO.FileMode.Open)
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin kBEL)
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl es(0), Nothing, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
MsgBox(FilteredDT.Rows.Cou nt)
Dim path As String = Application.ExecutablePath ()
For Each row In FilteredDT.Rows
row("Image").value = path & "Image\" & row("Image").value
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
Next
End Sub
End Class
LinkSearch.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<MyDataTable>
<LinkAID>1</LinkAID>
<Image>ImageA.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>2</LinkAID>
<Image>ImageB.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>3</LinkAID>
<Image>ImageC.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>4</LinkAID>
<Image>ImageD.jpg</Image>
</MyDataTable>
</Root>
forms.pptx
Below is the code and xml file containing the images for your information, hopefully you can duplicate the project from your end and test it with an image file. I am not able to upload the load the project.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshRe
End Sub
Private Sub ReportViewer1_Load(sender As Object, e As EventArgs)
End Sub
Public fslinkBEL As System.IO.FileStream
Public dtsetlinkBEL As New DataSet
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds = New DataSet()
ds.ReadXml(Application.Sta
ds.WriteXmlSchema(Applicat
Dim curfile As String = (Application.StartupPath + "\linkSearch.xml")
fslinkBEL = New System.IO.FileStream(Appli
dtsetlinkBEL.Clear()
dtsetlinkBEL.ReadXml(fslin
fslinkBEL.Close()
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl
FilteredDT = DV.ToTable
MsgBox(FilteredDT.Rows.Cou
Dim path As String = Application.ExecutablePath
For Each row In FilteredDT.Rows
row("Image").value = path & "Image\" & row("Image").value
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
Next
End Sub
End Class
LinkSearch.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<MyDataTable>
<LinkAID>1</LinkAID>
<Image>ImageA.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>2</LinkAID>
<Image>ImageB.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>3</LinkAID>
<Image>ImageC.jpg</Image>
</MyDataTable>
<MyDataTable>
<LinkAID>4</LinkAID>
<Image>ImageD.jpg</Image>
</MyDataTable>
</Root>
forms.pptx
ASKER
I tried your suggestion, no errors occurred but the images are not displayed.
then debug your app
and see what is assigned here
row("Image") = path & "Image\" & row("Image")
is that correct?
and see what is assigned here
row("Image") = path & "Image\" & row("Image")
is that correct?
ASKER
I am getting the wrong path
Debug\WindowsApplication2. EXEImage\I mageA.jpg
Victor
Debug\WindowsApplication2.
Victor
ASKER
When I try the code below to obtain the correct path, the images are still not displayed.
Dim path As String = Application.StartupPath()
For Each row In FilteredDT.Rows
row("Image") = path & "\Image\" & row("Image")
Dim path As String = Application.StartupPath()
For Each row In FilteredDT.Rows
row("Image") = path & "\Image\" & row("Image")
try using Application.StartupPath
Dim path As String = Application.StartupPath
For Each row In FilteredDT.Rows
row("Image").value = path & "Image\" & row("Image").value
ASKER
It still doesn't work, removed .Value to avoid the error but still doesn't work, the path is correct bu for some reason the images does not display, could it be a property needs to be set to view images?
if path is correct, then play with report parameters for image field...
ASKER
Trying different things in image properties but so far no luck.
try setting this
myReport.EnableExternalIma ges=true
check this video
https://www.youtube.com/watch?v=D4uU25NUy_4
myReport.EnableExternalIma
check this video
https://www.youtube.com/watch?v=D4uU25NUy_4
ASKER
Hi,
I followed the example for viewing external images, but the example is only for hard coding the external image in the code. How do I modify the code to include row (image) in the r(0)?. The code below in part B does not work, can't figure out how to include row(image) values in the following code: r(0) = New ReportParameter("ImageVar" , row("Image"), True). Code in Part A shows code in the video for hard coding an external file.
Part A:
Dim r(0) As ReportParameter
r(0) = New ReportParameter("ImageVar" , "files\" + "imagepath\image.jpg", True)
ReportViewer1.LocalReport. EnableExte rnalImages = True
ReportViewer1.LocalReport. SetParamet ers(New ReportParameter() {r(0)})
Part B
Dim r(0) As ReportParameter
ReportViewer1.LocalReport. EnableExte rnalImages = True
Dim path As String = Application.StartupPath
For Each row In FilteredDT.Rows
row("Image") = path & "\Image\" & row("Image")
r(0) = New ReportParameter("ImageVar" , row("Image"), True)
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
Next
Thanks,
Victor
I followed the example for viewing external images, but the example is only for hard coding the external image in the code. How do I modify the code to include row (image) in the r(0)?. The code below in part B does not work, can't figure out how to include row(image) values in the following code: r(0) = New ReportParameter("ImageVar"
Part A:
Dim r(0) As ReportParameter
r(0) = New ReportParameter("ImageVar"
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
Part B
Dim r(0) As ReportParameter
ReportViewer1.LocalReport.
Dim path As String = Application.StartupPath
For Each row In FilteredDT.Rows
row("Image") = path & "\Image\" & row("Image")
r(0) = New ReportParameter("ImageVar"
If FilteredDT.Rows.Count > 0 Then
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
Next
Thanks,
Victor
ASKER
HELP!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think the report parameter r(0) needs to be part of the code, similar to the example, only difference is solution of for specific image, I need to pass image value for each record.
Thanks,
Victor
Thanks,
Victor