Yes, this is possible. In the following example, the .rpt file can be uploaded and then set as the source of a standard ASP.NET CrystalReportViewer
control (in this case, reportViewer
).
using CrystalDecisions.CrystalReports.Engine;
...
ReportDocument document = new ReportDocument();
document.Load(reportPath); //"C:\\path\\to\\report\\file.rpt";
reportViewer.ReportSource = document;
reportViewer.RefreshReport();
If the database credentials embedded in the .rpt file are incorrect, they can be set as follows:
using CrystalDecisions.Shared;
...
private void ViewReport()
{
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.ServerName = "dbservername";
connInfo.DatabaseName = "dbname";
connInfo.UserID = "dbusername";
connInfo.Password = "dbpassword";
reportViewer.ReportSource = GetReportSource(connInfo);
reportViewer.RefreshReport();
}
private ReportDocument GetReportSource(ConnectionInfo connInfo)
{
ReportDocument document = new ReportDocument();
document.Load(reportPath); //"C:\\path\\to\\report\\file.rpt";
TableLogOnInfos logonInfos = new TableLogOnInfos();
TableLogOnInfo logonInfo = new TableLogOnInfo();
Tables tables;
tables = document.Database.Tables;
foreach(CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo = connInfo;
table.ApplyLogOnInfo(logonInfo);
}
return document;
}