Save and Load Report in Designer

This sample shows how to load report to the designer and how to use the save report event. 

private void btLoadReport_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (cbReports.SelectedItem != null)
{
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
var stream = a.GetManifestResourceStream(string.Format("DesignerSaveLoad.ReportFiles.{0}.mrt",
((ComboBoxItem)cbReports.SelectedItem).Content.ToString()));

StiReport report = new StiReport();
report.Load(stream);
stream.Close();
stream.Dispose();
stream = null;

report.CalculationMode = StiCalculationMode.Interpretation;
report.RegBusinessObject("Data", "Data", new Data());

designer.Report = report;
}
}


You can add the event listeners to the StiOptions.Engine.GlobalEvents at application initialization:

public MainPage()
{
...

StiOptions.Engine.GlobalEvents.SavingReportInDesigner +=
new Stimulsoft.Report.Design.StiSavingObjectEventHandler(GlobalEvents_SavingReportInDesigner);
}


Specify the action to be performed when the report is saving:

private void GlobalEvents_SavingReportInDesigner(object sender, Stimulsoft.Report.Design.StiSavingObjectEventArgs e)
{
if (designer.Report == null) return;
e.Processed = true;
messageBox = new MessageBoxWindow();
messageBox.Closed += delegate
{
if (messageBox.Result == MessageBoxResult.Yes)
{
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = "Report Files (*.mrt) | *.mrt";
if (saveDialog.ShowDialog() == true)
{
var stream = saveDialog.OpenFile();
StiXmlReportSLService saveService = new StiXmlReportSLService();
saveService.Save(designer.Report, stream);

stream.Flush();
stream.Close();
stream.Dispose();
stream = null;
}
}

messageBox = null;
};

messageBox.Show();
}


In the screenshot below you can see the result of the sample code.

Save and Load Report in Designer