Hi,
I'm creating a new report in code and would like when the user clicks the save button first that the default directory will be e.g.
string reportPath = @"C:\data\reports";
StiOptions.Preview.Window.ReportSaveLoadPath = reportPath;
StiOptions.Designer.ReportSaveLoadPath = reportPath;
I tried the above options but the directory always defaults to the last saved directory rather then @"C:\data\reports";
Even this doesn't work:
Environment.CurrentDirectory = reportPath;
What can I do please?
Thanks,
Patrick
PS: Using Version 2009.2.422.0
Set default report path with ReportSaveLoadPath
Set default report path with ReportSaveLoadPath
Hi Patrick,
Yes, you are right. The properties:
StiOptions.Preview.Window.ReportSaveLoadPath = reportPath;
StiOptions.Designer.ReportSaveLoadPath = reportPath;
will work only for 'Save' buttons in the preview control and in the designer control respectively.
If you need control over 'Save as' button in the designer, then please reassign SaveAs event handler as follows:
Thank you.
Yes, you are right. The properties:
StiOptions.Preview.Window.ReportSaveLoadPath = reportPath;
StiOptions.Designer.ReportSaveLoadPath = reportPath;
will work only for 'Save' buttons in the preview control and in the designer control respectively.
If you need control over 'Save as' button in the designer, then please reassign SaveAs event handler as follows:
Code: Select all
private void Form1_Load(object sender, EventArgs e)
{
StiOptions.Viewer.Windows.ReportSaveLoadPath = "c:\\";
StiOptions.Designer.ReportSaveLoadPath = "c:\\";
StiReport report = new StiReport();
report = new StiReport();
// you can also hide Save As button
//StiMainMenuService mainMenuService = StiMainMenuService.GetService();
//mainMenuService.ShowFileReportSaveAs = false;
StiDesigner.SavingReport += new StiSavingObjectEventHandler(On_SavingReport);
StiDesigner.DontAskSaveReport = true;
report.Design();
}
private void On_SavingReport(object sender, StiSavingObjectEventArgs e)
{
StiReport report = (sender as StiDesignerControl).Report;
// Checking if the filename to save is known or not
// If you set static option StiDesigner.DontAskSaveReport = true, then e.SaveAs is true only when SaveAs button is pressed.
if (e.SaveAs == true)
{
SaveFileDialog mySaveDialog = new SaveFileDialog();
mySaveDialog.InitialDirectory = "D:\\";
mySaveDialog.DefaultExt = ".mrt";
mySaveDialog.FileName = Path.GetFileNameWithoutExtension((sender as StiDesignerControl).ReportFileName);
do
{
if (mySaveDialog.ShowDialog() == DialogResult.OK)
{
if (Path.GetDirectoryName(mySaveDialog.FileName) == mySaveDialog.InitialDirectory)
{
report.Save(mySaveDialog.FileName);
MessageBox.Show("Saving complete.");
(sender as StiDesignerControl).ReportFileName = mySaveDialog.FileName;
e.Processed = true;
}
else
{
MessageBox.Show("You can save the report only in " + mySaveDialog.InitialDirectory.ToString() + " folder.");
}
}
else
{
break;
}
}
while (Path.GetDirectoryName(mySaveDialog.FileName) != mySaveDialog.InitialDirectory);
}
else
{
//Here is the code which fires after the filename had been set to the specified folder
report.Save(report.ReportFile);
}
}
Set default report path with ReportSaveLoadPath
Hi Edward,
thank you very much for your detailed answer... Here is what I ended up using in case it helps anybody else.
All the best,
Patrick
thank you very much for your detailed answer... Here is what I ended up using in case it helps anybody else.
All the best,
Patrick
Code: Select all
StiDesigner.DontAskSaveReport = true;
StiDesigner.SavingReport += On_SavingReport;
private void On_SavingReport(object sender, StiSavingObjectEventArgs e)
{
StiDesignerControl stiDesignerControl = sender as StiDesignerControl;
if (stiDesignerControl == null)
return;
StiReport report = stiDesignerControl.Report;
// Checking if the filename to save is known or not
// If you set static option StiDesigner.DontAskSaveReport = true, then e.SaveAs is true only when SaveAs button is pressed.
if (e.SaveAs || String.IsNullOrEmpty(report.ReportFile))
{
var saveDialog = new SaveFileDialog
{
CheckPathExists = true,
OverwritePrompt = true,
SupportMultiDottedExtensions = false,
ValidateNames = true,
Title = "Please choose a new report file",
Filter = "Report files (*.mrt)|*.mrt",
DefaultExt = ".mrt",
AddExtension = true,
AutoUpgradeEnabled = true,
InitialDirectory = ReportFullPath,
FileName = Path.GetFileNameWithoutExtension(stiDesignerControl.ReportFileName)
};
do
{
if (saveDialog.ShowDialog() == DialogResult.OK)
{
if (Path.GetDirectoryName(saveDialog.FileName) == saveDialog.InitialDirectory)
{
report.Save(saveDialog.FileName);
stiDesignerControl.ReportFileName = saveDialog.FileName;
e.Processed = true;
}
else
{
MessageBox.Show("You can save the report only in " + saveDialog.InitialDirectory.ToString() + " folder.");
saveDialog.FileName = Path.GetFileNameWithoutExtension(saveDialog.FileName);
}
}
else
break;
}
while (Path.GetDirectoryName(saveDialog.FileName) != saveDialog.InitialDirectory);
}
else
{
//Here is the code which fires after the filename had been set to the specified folder
report.Save(report.ReportFile);
}
}
Set default report path with ReportSaveLoadPath
Thank you Patrick, very helpful code here.