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.
答案 0 :(得分:3)
将以下代码添加到您的项目中:
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);
然后在报表设计器中,确保Image项在External
上设置了图像源属性,并且您具有正确名称的参数(ImgPath)。然后只需定义一个指向右图像的表达式。 (这将取决于您在数据库中存储图像名称的方式,我们没有扩展名,我假设您添加了扩展名)
= Parameters!ImgPath.Value + Fields!PersonalInfoEmployeePicture.Value