I would like to extract the SQL queries from Crystal Report .rpt files, is there a way to do this?
I don\'t have any of the Crystal Reports products, just the .rpt files
JoshL's answer worked for several of my reports, but not all of them. The following method, using ReportClientDocument.RowsetController.GetSQLStatement
, was able to extract some of the queries that the other method missed.
foreach (string file in Directory.GetFiles("c:\\projects\\Reports", "*.rpt"))
{
Console.WriteLine(String.Format("Processing {0}...", file));
var doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
doc.Load(file);
var controller = doc.ReportClientDocument.RowsetController;
var groupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
string temp = String.Empty;
string commandSql = controller.GetSQLStatement(groupPath, out temp);
//TODO: do something with commandSql
}