Create a copy of a report or import a report file (.rptx)

102
1
Jump to solution
01-21-2022 02:05 PM
PierreMasson
New Contributor III

Hi,

We are developing an add-in and we will need to have a lot of reports. Our reports are huge and will have to be in french or English. We don't want to be maintaining 2 versions of a report (one with French labels, the other with English labels). 

So we have created the report using our special tags in the labels and when we are generating the report (programatically) we inject the appropriate string in all the labels using resource files. That works well.

But then, the report is change forever. So we want to make a copy of the base report under another name, then inject the strings in the labels, then generate that copy of the report.

I did not found a way to copy a project item. Can it be done?

The other approach I tried was to import a rptx file. I included my rptx file in my addin, I copy the file under another name and try to create a project item from that and it fails. I saw the CIMReportDocument class that has a fromJson method. But I don't know how I can go from CIMReportDocument to a ArcGIS.Desktop.Reports.Report.

Can you help please?

How can we create a copy of a project Item?
How can we import a rptx file programmatically and add it to the project catalog?

0 Kudos
1 Solution

Accepted Solutions
PierreMasson
New Contributor III

Found it by myself...

ReportProjectItem reportProjItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportNameToImport));
report = reportProjItem?.GetReport();

Report newReport = ReportFactory.Instance.CopyReport(report);

View solution in original post

0 Kudos
1 Reply
PierreMasson
New Contributor III

Found it by myself...

ReportProjectItem reportProjItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportNameToImport));
report = reportProjItem?.GetReport();

Report newReport = ReportFactory.Instance.CopyReport(report);
0 Kudos