Victor Charles
asked on
Help with viewing image in ReportViewer
Hi,
I included an Image field in my report, how do I view the images(jpeg) from an image subfolder in my application folder?
Thanks,
Victor
I included an Image field in my report, how do I view the images(jpeg) from an image subfolder in my application folder?
Thanks,
Victor
Try this code
ReportViewer1.LocalReport.EnableExternalImages = true;
string imagePath = new Uri(Server.MapPath("~/images/yourimage.jpg")).AbsoluteUri; // Give your path here
ReportParameter parameter = new ReportParameter("ImagePath", imagePath);
ReportViewer1.LocalReport.SetParameters(parameter);
ReportViewer1.LocalReport.Refresh();
ASKER
Hi,
To clarify, This is a Windows application. I have multiple images in the image subfolder. The images names are in the image field of the database use to retrieve display each record.
Thanks,
Victor
To clarify, This is a Windows application. I have multiple images in the image subfolder. The images names are in the image field of the database use to retrieve display each record.
Thanks,
Victor
The images names are in the image field of the database use to retrieve display each record.are you using the MSSQL ? what ver?
can you provide as the script of creating that table?
ASKER
Hi,
The images' names are in the image field of a datatable which was converted from an xml file. The images(jpeg) are in the images subfolder.
V.
The images' names are in the image field of a datatable which was converted from an xml file. The images(jpeg) are in the images subfolder.
V.
ok, I think in general @Dorababu and I referring to the same technique in which we need to create a parameter in the report, and then we need to pass the image path to the report via this parameter.
not really done this before, but it seems it's the way to go.
not really done this before, but it seems it's the way to go.
Charles even though it is a windows application the code will be similar I guess, if not please attach sample screen shots how you want the output to be
ASKER
Hi?
How do I modify the code to display images for each record instead of hardcodong one image file as shown in the code (yourimage
jpg) ?
Thanks,
Victor
How do I modify the code to display images for each record instead of hardcodong one image file as shown in the code (yourimage
jpg) ?
Thanks,
Victor
Let us say you have a dataset which is having image names then you can loop and give the respective image name, a rough idea
foreach(DataRow dr in DataSet.Tables[0].Rows)
{
ReportViewer1.LocalReport.EnableExternalImages = true;
string imagePath = Path.Combine(
HttpContext.Current.Server.MapPath("~/images/"),dr["ImageName"].ToString(),".jpg");
ReportParameter parameter = new ReportParameter("ImagePath", imagePath);
ReportViewer1.LocalReport.SetParameters(parameter);
ReportViewer1.LocalReport.Refresh();
}
ASKER
Dorababu,
Can you please send me the VB.NET version of the code..
Thanks,
Victor
Can you please send me the VB.NET version of the code..
Thanks,
Victor
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 am trying the code below for the Windows version, but image still does not appear, the images were converted to .PNG to reduce their sizes. Any ideas why the code is not working? Should there be other setting in the properties sections?
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl es(0), SearchCriteria, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
If FilteredDT.Rows.Count > 0 Then
MsgBox(FilteredDT.Rows.Cou nt)
Label8.Text = FilteredDT.Rows.Count
FilteredDT.WriteXml((Appli cation.Sta rtupPath + "\SearchResults.xml"))
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
Dim imagePath As String = (Application.StartupPath + "\Images\")
Dim parameter As New ReportParameter("ImagePath ", imagePath)
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
Thanks,
V.
Dim FilteredDT As DataTable
Dim DV As New DataView(dtsetlinkBEL.Tabl
FilteredDT = DV.ToTable
If FilteredDT.Rows.Count > 0 Then
MsgBox(FilteredDT.Rows.Cou
Label8.Text = FilteredDT.Rows.Count
FilteredDT.WriteXml((Appli
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "DataSet1"
reportDataSource.Value = FilteredDT
Dim imagePath As String = (Application.StartupPath + "\Images\")
Dim parameter As New ReportParameter("ImagePath
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
Thanks,
V.
ASKER
Hi,
I decided to start a new project using code below but receiving error message: 'The source of the report definition has not been specified"
How do I fix this error?
In the properties section I have the following:
EnableExternalImages = True
ReportEmbeddedresoure = WindowsApplocation1.Report 1.dlc
Image Properties:
Select Image source: external
Use this image: [@ImagePath]
Code:
Imports Microsoft.Reporting.WinFor ms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshRe port()
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 curfile As String = (Application.StartupPath + "\linkSearchnew.xml")
fslinkBEL = New System.IO.FileStream(Appli cation.Sta rtupPath + "\LinkSearchnew.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
Dim imagePath As String = (Application.StartupPath + "\Images\")
Dim parameter As New ReportParameter("ImagePath ", imagePath)
ReportViewer1.LocalReport. DataSource s.Clear()
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
End If
End Sub
End Class
I decided to start a new project using code below but receiving error message: 'The source of the report definition has not been specified"
How do I fix this error?
In the properties section I have the following:
EnableExternalImages = True
ReportEmbeddedresoure = WindowsApplocation1.Report
Image Properties:
Select Image source: external
Use this image: [@ImagePath]
Code:
Imports Microsoft.Reporting.WinFor
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshRe
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 curfile As String = (Application.StartupPath + "\linkSearchnew.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
Dim imagePath As String = (Application.StartupPath + "\Images\")
Dim parameter As New ReportParameter("ImagePath
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
End If
End Sub
End Class
ASKER
Thank You.
for your ref:
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net
https://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx
Display external Image in Microsoft Report viewer (.rdlc) file
https://sansknowledge.wordpress.com/2014/10/18/display-external-image-in-microsoft-report-viewer-rdlc-file/