public int GetReportsList(string[] reports) { string sSSRSPath = this.mSSRSPath; int reportCount = 0; if (string.IsNullOrEmpty(SSRSPath)) throw new ArgumentNullException("Please provide a valid SSRS path for the parent folder."); try { if (this.mDefaultCredentials == true) mReportingService.Credentials = CredentialCache.DefaultCredentials; else mReportingService.Credentials = new NetworkCredential(this.mUsername, this.mPassword, this.mDomain); CatalogItem[] oItems = mReportingService.ListChildren(SSRSPath, true); foreach (CatalogItem oItem in oItems) { string sItemType = oItem.TypeName; Report oReport = this.GetReport(oItem); try { if (sItemType == "Report") { if (reports.FirstOrDefault(r => r.Equals(oReport.Path)) == null) continue; // Call ReportFoundEventHandler ReportFoundEvent oReportFoundEvent = new ReportFoundEvent(); oReportFoundEvent.SetReport(oReport); ReportFound(this, oReportFoundEvent); reportCount++; } } catch (Exception er) { ReportFailEvent oReportFailEvent = new ReportFailEvent(); oReportFailEvent.SetException(er); oReportFailEvent.SetErrorMessage(er.Message); ReportFail(this, oReportFailEvent); } } return reportCount; } catch (Exception er) { throw new Exception(string.Format("Failed to get reports: {0}", er.Message)); } }
public void ExportReportsFromList() { string SSRSPath = this.mSSRSPath; string ExportPath = this.mExportPath; List<string> ReportsList = this.mReportsList; List<string> ReportsExportedList = new List<string>(); if (string.IsNullOrEmpty(SSRSPath)) throw new ArgumentNullException("Please provide a valid SSRS path for the parent folder."); if (string.IsNullOrEmpty(ExportPath)) throw new ArgumentNullException("Please provide a valid export path."); if (mReportsList == null) throw new ArgumentNullException("Please provide a valid reports list."); try { if (this.mDefaultCredentials == true) mReportingService.Credentials = CredentialCache.DefaultCredentials; else mReportingService.Credentials = new NetworkCredential(this.mUsername, this.mPassword, this.mDomain); CatalogItem[] oItems = mReportingService.ListChildren(SSRSPath, this.mRecursiveList); foreach (CatalogItem oItem in oItems) { string sItemType = oItem.TypeName; Report oReport = this.GetReport(oItem); string sReportExportPath = string.Format("{0}{1}.rdl", ExportPath, oItem.Path.Replace('/', '\\')); try { if (sItemType == "Report") { // Only export the report if its in our list of reports if (ReportsList.Find(r => r == oItem.Path) == null) continue; // Call ReportExportReportFoundEventHandler ReportFoundEvent oReportFoundEvent = new ReportFoundEvent(); oReportFoundEvent.SetReport(oReport); ReportFound(this, oReportFoundEvent); byte[] oReportDefinition = null; oReportDefinition = mReportingService.GetItemDefinition(oItem.Path); // Do export this.SaveReport(sReportExportPath, oReportDefinition, true); // Call ReportExportSuccessEventHandler ReportExportSuccessEvent oReportSuccessEvent = new ReportExportSuccessEvent(); oReportSuccessEvent.SetExportedPath(sReportExportPath); oReportSuccessEvent.SetReport(oReport); ReportExportedSuccess(this, oReportSuccessEvent); } //else if (sItemType == "DataSource") //{ // // Call DataSourceFoundEventHandler // DataSourceFoundEvent oDataSourceFoundEvent = new DataSourceFoundEvent(); // oDataSourceFoundEvent.setSSRSPath(oItem.Path); // DataSourceFound(this, oDataSourceFoundEvent); // string sDataSourceExportPath = string.Format("{0}{1}.json", ExportPath, oItem.Path.Replace('/', '\\')); // string output = GetDataSource(oItem.Path); // SaveDataSource(sDataSourceExportPath, output, true); // // Call DataSourceExportSuccessEventHandler // DataSourceExportSuccessEvent oDataSourceSuccessEvent = new DataSourceExportSuccessEvent(); // oDataSourceSuccessEvent.setDataSourceText(output); // oDataSourceSuccessEvent.setPath(sDataSourceExportPath); // oDataSourceSuccessEvent.setSSRSPath(oItem.Path); // DataSourceExportedSuccess(this, oDataSourceSuccessEvent); //} } catch (Exception er) { ReportExportFailEvent oReportFailEvent = new ReportExportFailEvent(); oReportFailEvent.SetException(er); oReportFailEvent.SetErrorMessage(er.Message); oReportFailEvent.setReport(oReport); oReportFailEvent.SetExportedPath(sReportExportPath); ReportExportFail(this, oReportFailEvent); } } } catch (Exception er) { throw new Exception(string.Format("Failed to export reports: {0}", er.Message)); } }