1

I am storing picture name only in database, actual picture gets stored in project directory 'SiteImages'.

Now I want to display the image in RDLC report but not getting displayed. CODE:

public void Fill_AuditsReport()
{
    ReportViewer1.AsyncRendering = false;
    ReportViewer1.SizeToReportContent = true;
    ReportViewer1.ZoomMode = ZoomMode.FullPage;
    this.ReportViewer1.Reset();

    DataTable dt = new DataTable();
    PersonalInfo.ManagePersonalInfo MngPersonalInfo = new PersonalInfo.ManagePersonalInfo();

    dt = MngPersonalInfo.ReportSelectPersonalInfo();

    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/DataManagementReports/Report.rdlc");
    ReportDataSource rpds = new ReportDataSource("DataSetPersonalInfo", dt);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rpds);
    ReportViewer1.Visible = true;
}

the name of the field in database is PersonalInfoEmployeePicture.

leppie
  • 115,091
  • 17
  • 196
  • 297
Juventus tech
  • 95
  • 4
  • 13

1 Answers1

4

Add the following code to your project:

ReportViewer1.LocalReport.EnableExternalImages = true;
string FilePath = @"file:\" + Application.StartupPath + "\\" + "SiteImages\\"; //Application.StartupPath is for WinForms, you should try AppDomain.CurrentDomain.BaseDirectory  for .net
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("ImgPath", FilePath);
ReportViewer1.LocalReport.SetParameters(param);

Then in the report designer, make sure the Image item has the image source property set on External and you have a parameter with the correct name (ImgPath). Then simply define an expression that directs to the right image. (This will vary depending on how you stored the image namein the database, with our without extension, I'm assuming you added the extension)

= Parameters!ImgPath.Value + Fields!PersonalInfoEmployeePicture.Value
Oceans
  • 3,445
  • 2
  • 17
  • 38
  • Then the above expression should be correct if the FilePath is correct. – Oceans Nov 12 '15 at 12:58
  • I am getting error at SetParameters and StartUpPath. Doesn't contain definition for specified methods – Juventus tech Nov 12 '15 at 12:59
  • The FilePath string should basically have the location of the image folder, as for the reason of SetParameters failing, I forgot to mention you'll have to create the parameter `ImgPath` in the designer. – Oceans Nov 12 '15 at 13:02
  • yes sir but problem is that I am getting error at StartUpPath and SetParameters, kinda RED UNDERLINE. – Juventus tech Nov 12 '15 at 13:07
  • `Application.StartupPath` only works in win forms, you should try `AppDomain.CurrentDomain.BaseDirectory` for the root directory of your project. You could also just define the exact path name if you know it. And as for the second error, try `ReportViewer1.LocalReport.SetParameters(param)`my bad – Oceans Nov 12 '15 at 13:12
  • can you connect on team viewer for a minute ? i a on very tight deadline adn will be thank ful to you – Juventus tech Nov 12 '15 at 13:17
  • Thanks a lot it's done, i left that parameter part and when i followed you then it worked – Juventus tech Nov 12 '15 at 13:36