Ok, so dotjoe gave me all the hints I needed for this. The following code can be used to display command text from a crystal report.
public string getCommandText(ReportDocument rd) { if (!rd.IsLoaded) throw new ArgumentException("Please ensure that the reportDocument has been loaded before being passed to getCommandText"); PropertyInfo pi = rd.Database.Tables.GetType().GetProperty("RasTables", BindingFlags.NonPublic | BindingFlags.Instance); return ((dynamic)pi.GetValue(rd.Database.Tables, pi.GetIndexParameters()))[0].CommandText; }
It looks a little dirty, but it makes some sense when you start to wade through it. Basically, it uses reflection to get the value of the CommandText property, with little dynamics to get the dynamic properties in the ReportDocument.
This pulls the command text for me, but I did not have time to do any code tests. I am sure that I will make some adjustments as soon as I have time to work with this. I do not know what happens with reports that do not use "SQL Commands". I will post a comment after I have verified this further.
PS This requires that you reference the standard reflection / dynamic display libraries, as well as the following Crystal Report libraries:
crystaldecisions.reportappserver.datadefmodel
crystaldecisions.crystalreports.engine
crystaldecisions.shared
Chronicide
source share