Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

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
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

there could be ways we can do it.

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/
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();

Open in new window

Avatar of Victor  Charles

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
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?
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.
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.
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
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
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();
}

Open in new window

Dorababu,

Can you please send me the VB.NET version of the code..

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Avatar of Dorababu M
Dorababu M
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.Tables(0), SearchCriteria, Nothing, DataViewRowState.CurrentRows)
        FilteredDT = DV.ToTable
        If FilteredDT.Rows.Count > 0 Then
            MsgBox(FilteredDT.Rows.Count)
            Label8.Text = FilteredDT.Rows.Count
            FilteredDT.WriteXml((Application.StartupPath + "\SearchResults.xml"))

            Dim reportDataSource As New Microsoft.Reporting.WinForms.ReportDataSource()
            reportDataSource.Name = "DataSet1"
            reportDataSource.Value = FilteredDT
            Dim imagePath As String = (Application.StartupPath + "\Images\")
            Dim parameter As New ReportParameter("ImagePath", imagePath)
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.DataSources.Add(reportDataSource)
            ReportViewer1.LocalReport.Refresh()
            ReportViewer1.RefreshReport()

Thanks,

V.
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.Report1.dlc

Image Properties:

Select Image source: external
Use this image: [@ImagePath]


Code:

Imports Microsoft.Reporting.WinForms

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.ReportViewer1.RefreshReport()
    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(Application.StartupPath + "\LinkSearchnew.xml", IO.FileMode.Open)
        dtsetlinkBEL.Clear()
        dtsetlinkBEL.ReadXml(fslinkBEL)
        fslinkBEL.Close()


        Dim FilteredDT As DataTable
        Dim DV As New DataView(dtsetlinkBEL.Tables(0), Nothing, Nothing, DataViewRowState.CurrentRows)
        FilteredDT = DV.ToTable
        If FilteredDT.Rows.Count > 0 Then
            Dim reportDataSource As New Microsoft.Reporting.WinForms.ReportDataSource()
            reportDataSource.Name = "DataSet1"
            reportDataSource.Value = FilteredDT
            Dim imagePath As String = (Application.StartupPath + "\Images\")
            Dim parameter As New ReportParameter("ImagePath", imagePath)
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.DataSources.Add(reportDataSource)
            ReportViewer1.LocalReport.Refresh()
            ReportViewer1.RefreshReport()
        End If
    End Sub
End Class
Thank You.