Windows Forms: Display Image in Report Viewer using C#

Dynamically Display/Add Image to Report Viewer in C#

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "RDLCWithImage" and then click OK

rdlc with image in c#Step 2: Design your form as below

Name your main form: Form1

rdlc with image in c#

Name your print form: frmPrint

rdlc with image in c#

Add a Report Viewer to your print form

You can design your report as below

rdlc report with image in c#

Add code to handle Form1 form

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    string imageUrl = null;
    private void btnBrowse_Click(object sender, EventArgs e)
    {
        //Select an image, then display to the picturebox control
        using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg" })
        {
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                imageUrl = ofd.FileName;
                pictureBox.Image = Image.FromFile(ofd.FileName);
            }
        }
    }

    private void btnPrint_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(imageUrl))
        {
            //Open print form
            using (frmPrint frm = new frmPrint(imageUrl))
            {
                frm.ShowDialog();
            }
        }
    }
}

Add code to handle frmPrint form

public partial class frmPrint : Form
{
    string _imageUrl;
    public frmPrint(string imageUrl)
    {
        InitializeComponent();
        _imageUrl = imageUrl;
    }

    private void frmPrint_Load(object sender, EventArgs e)
    {
        //Read image from file, then set to report parameter
        FileInfo fi = new FileInfo(_imageUrl);
        ReportParameter pName = new ReportParameter("pName", fi.Name);
        ReportParameter pImageUrl = new ReportParameter("pImageUrl", new Uri(_imageUrl).AbsoluteUri);
        this.reportViewer1.LocalReport.EnableExternalImages = true;
        this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { pName, pImageUrl });
        this.reportViewer1.RefreshReport();
    }
}

VIDEO TUTORIALS