Page 1 of 1
Clone Report Page
Posted: Thu May 22, 2014 7:43 pm
by jamesmuir
I am trying to clone a report page based on the discussion found here
http://forum.stimulsoft.com/viewtopic.php?f=9&t=36686
I have implemented the following code
Code: Select all
var report = new StiReport();
var reportPath = @"C:\Users\james_000\Documents\Visual Studio 2013\Projects\ReportTest\Templates\Dynamic.mrt";
report.Load(reportPath);
Stimulsoft.Report.Components.StiPage newPage = report.Pages[0].Clone() as Stimulsoft.Report.Components.StiPage;
var image = newPage.Components[newPage.Components.IndexOf("Image1")] as Stimulsoft.Report.Components.StiImage;
image.ImageURL = new Stimulsoft.Report.Components.StiImageURLExpression("http://tweeterism.com/wp-content/uploads/2013/04/LOL-Cat.jpeg");
report.Pages.Add(newPage);
report.Compile();
report.Render();
StiPdfExportService pdfExport = new StiPdfExportService();
pdfExport.ExportPdf(report, @"C:\Users\james_000\Documents\Visual Studio 2013\Projects\ReportTest\output\dyanmic.pdf");
However, when i try to run the code i get an exception that states
Code: Select all
error CS0102: The type 'Reports.Report' already contains a definition for 'Page1'
Can someone let me know if what I am trying to do is possible?
Sample application with the report template can be found here to view the problem in action.
Re: Clone Report Page
Posted: Fri May 23, 2014 12:46 pm
by HighAley
Hello.
Please, try to change the Name of the page.
As a way you can render report once and save rendered pages. Than make changes and render report again. Copy rendered pages to the first one.
Thank you.
Re: Clone Report Page
Posted: Sun May 25, 2014 3:09 pm
by jamesmuir
I am changing the name of the page in the test project that I have provided a link to but it appears that the other controls pose the same problem. I also tried to recursively change the name of the all of the controls in the duplicated page and recieve the message
Code: Select all
Additional information: zlx2pzit.0.cs(27,53) : error CS0102: The type 'Reports.Report' already contains a definition for 'Text' zlx2pzit.0.cs(37,21) : error CS0111: Type 'Reports.Report' already defines a member called 'Text__GetValue' with the same parameter types
It would seem to me that rendering each page would cause a drastic hit in performance if I proceed that way. I was wondering how you able to get this functionality to work in the link that I provided in my previous post?
Re: Clone Report Page
Posted: Mon May 26, 2014 12:57 pm
by Alex K.
Hello,
Unfortunately, the Clone method was changed and cannot been used in this case.
You can render report once and save rendered pages. Than make changes and render report again. Copy rendered pages to the first one.
Thank you.
Re: Clone Report Page
Posted: Tue May 27, 2014 5:27 pm
by jamesmuir
I have tried creating a new temp report and rendering the cloned page inside of that to copy over using this code.
Code: Select all
//Create temp Report for page rendering
StiReport tempReport = new StiReport();
//Get the new pages
Stimulsoft.Report.Components.StiPage newPage = report.Pages[0].Clone() as Stimulsoft.Report.Components.StiPage;
newPage.Name = "newPage";
var image = newPage.Components[newPage.Components.IndexOf("Image")] as Stimulsoft.Report.Components.StiImage;
image.ImageURL = new Stimulsoft.Report.Components.StiImageURLExpression("http://tweeterism.com/wp-content/uploads/2013/04/LOL-Cat.jpeg");
tempReport.Pages.Add(newPage);
tempReport.Render();
However, it throws an System.NullReferenceException when i try to render the temp report. Could provide an example of adding a new page to a report and rendering it successfully so that the page appears when the report is exported?
I uploaded my current project here
2 for you to view as well.
Re: Clone Report Page
Posted: Wed May 28, 2014 6:38 am
by Alex K.
Hello,
Please do not use the Clone method. Please try to use th following:
- render report, save rendered pages in temporary report;
- change the necessary item in original report
- render again original report and add rendered pages in temporary report;
- export temporary report;
Thank you.
Re: Clone Report Page
Posted: Wed May 28, 2014 1:33 pm
by jamesmuir
I removed the code for clone and tried to add the rendered page to a new report created in code. I am clearing the pages in the new report when it is first created and then adding the page. When I try this i receive the error
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Code: Select all
//Create temp Report for page rendering
StiReport tempReport = new StiReport();
tempReport.Pages.Clear();
tempReport.Pages.Add(report.Pages[0]);
tempReport.Render();
If I render the new report after I clear the pages and before I add the new page I do not get this error but I the exported report does not contain the page I added.
Code: Select all
//Create temp Report for page rendering
StiReport tempReport = new StiReport();
tempReport.Pages.Clear();
tempReport.Render();
tempReport.Pages.Add(report.Pages[0]);
tempReport.Render();
This code also does not work
Code: Select all
StiReport tempReport = new StiReport();
tempReport.Pages.Clear();
tempReport.Render();
tempReport.RenderedPages.Add(report.RenderedPages[0]);
tempReport.Render();
Again, I have uploaded the project here
http://www.filedropper.com/. This appears to be the simplest implementation of the code yet I am still not able to achieve the desired results of using a single page as a template for other pages. Can you let me know if this is a feasible goal using this software and, if so, where my approach is flawed? Thank you.
Re: Clone Report Page
Posted: Fri May 30, 2014 7:10 am
by Alex K.
Hello,
Please check the modified project in the attachment.
Thank you.