We help IT Professionals succeed at work.

Help with viewing image in ReportViewer

637 Views
Last Modified: 2017-05-25
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
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
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/
Dorababu MSenior Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
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

Author

Commented:
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
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
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.
Dorababu MSenior Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
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

Author

Commented:
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
Dorababu MSenior Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
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

Author

Commented:
Dorababu,

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

Thanks,

Victor
Senior Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2018
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Author

Commented:
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

Author

Commented:
Thank You.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.