Download CRM Reports using SDK
Views (1927)
Download CRM Reports using SDK
I recently got a request to download all the report rdl files. Because of the number of reports it would take forever, so using the CRM SDK you can easily download rdl files.
I use generated entities but you can use dynamic entity values as well.
// Get list of all reports
List<Report> reports = (from rp in service.ReportSet
select new Report
{
ReportId = rp.ReportId,
Name = rp.Name,
Description = rp.Description,
FileName = rp.FileName
}).ToList();
foreach (Report report in reports)
{
// Use the path defined in a textbox on a windows form..
// You can also change this value to your destination
string reportPath = Path.Combine(txtPath.Text, report.Name);
filename = report.FileName;
if (!Directory.Exists(reportPath))
{
Directory.CreateDirectory(reportPath);
}
// Use the Download Report Definition message.
DownloadReportDefinitionRequest rdlRequest = new DownloadReportDefinitionRequest
{
ReportId = report.ReportId.Value
};
DownloadReportDefinitionResponse rdlResponse = (DownloadReportDefinitionResponse)service.Execute(rdlRequest);
// Access the xml data and save to disk
XmlTextWriter reportDefinitionFile = new XmlTextWriter(reportPath + "\\" + report.FileName, System.Text.Encoding.UTF8);
reportDefinitionFile.WriteRaw(rdlResponse.BodyText);
reportDefinitionFile.Close();
The post Download CRM Reports using SDK appeared first on Cup of dev - A blog for developers by Morne Wolfaardt.
This was originally posted here.

Like
Report
*This post is locked for comments