I currently working on retro fitting some SQL server reports into the application we are building. I needed a quick way to view all the parameters each report uses. The code below is a quick snippet to do just that. Just point it at a directory with the RDL files in an away you go. Note: This code does the bare minimum and is used for SQL Server 2005 RDL. I haven't checked to see if it works on SQL 2008 RDL. Thought it might help someone.
public Report()
{
Parameters = new List<Parameter>();
}
public string ReportName { get; set; }
public List<Parameter> Parameters{ get; set;}
}
///
/// Represents a report parameter.
///
public class Parameter
{
public string Name { get; set; }
public string DataType { get; set; }
public string DefaultValue { get; set; }
public string Hidden { get; set; }
///
/// Gets the report parameters.
///
public static List<Report> GetReportParameters(string location)
{
if (!Directory.Exists(location.Trim()))
Console.WriteLine("Could not find the location specified");
//Get the RDL files
var directoryInfo = new DirectoryInfo(location);
var rdlFiles = directoryInfo.GetFiles("*.rdl");
var reports = new List<Report>();
//For each file we will extract the parameters.
foreach(var fileInfo in rdlFiles)
{
var report = new Report {ReportName = fileInfo.Name};
var xDocument = XDocument.Load(File.OpenText(fileInfo.FullName));
var parameters =
xDocument.Descendants()
.Where(node => node.Name.LocalName == "ReportParameters")
.Nodes()
.Select(param => XElement.Load(param.CreateReader()))
.Select
(
param =>
new Parameter()
{
DataType = SafeRead(() => param.Elements().FirstOrDefault(xe => xe.Name.LocalName == "DataType").Value),
Hidden = SafeRead(() =>param.Elements().FirstOrDefault(xe => xe.Name.LocalName == "Hidden").Value),
Name = SafeRead(()=>param.Attribute("Name").Value)
}
)
.ToList();
report.Parameters.AddRange(parameters);
reports.Add(report);
}
return reports;
}