Report.AssignAll

jose525jose525 Deutschland
edited 5:59AM in FastReport .NET
Hi,
how do I create a 100% copy of a loaded report?

My current code looks like this:

template = Report.FromFile(filename);
...
report = new Report();
report.AssignAll(template);
...

it works file - all objects will be copied, but without names.

...
rect = report.FindObject("myDataRectangle");

if (rect == null)
MessageBox.Show("rect is null");
...

Please point me.

Thank you.

Comments

  • jose525jose525 Deutschland
    edited 5:59AM
    again me and I found a solution (maybe it isn't nice, but it works)

    public void CopyReport(Base source, Base target)
    {
    Base targetItem;


    target.Assign(source);
    target.Name = source.Name;

    foreach (Base sourceItem in source.ChildObjects)
    {
    targetItem = (Base)Activator.CreateInstance(sourceItem.GetType());
    targetItem.SetReport(target.Report);

    CopyReport(sourceItem, targetItem);

    targetItem.SetReport(null);
    targetItem.Parent = target;
    }
    }


    It works for me.

    Did someone have some other ideas?
  • edited 5:59AM
    Hello,

    The easiest way to copy a report instance is the following:
    Report report1 = new Report();
    report1.Load(...);
    Report report2 = new Report();
    report2.LoadFromString(report1.SaveToString());
    

    the fastest way is:
    Report report1 = new Report();
    report1.Load(...);
    Report report2 = new Report();
    using (MemoryStream stream = new MemoryStream())
    {
      report1.Save(stream);
      stream.Position = 0;
      report2.Load(stream);
    }
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.