In the designer i need that the user can save the layout only in a certain folder.
I have tried using the "SavingReport" event, but it is fired before the "save as" dialog appears, so the user has not yet choosen the destination folder.
For me it would be ok if, when the user confirms the saving folder in the designer, i can check if the folder is right and, if not, i send him a message and the report is not saved.
May i do this?
Thanks.
"save as" only in a certain folder
- Fabio Pagano
- Posts: 355
- Joined: Mon Apr 16, 2007 12:38 pm
- Location: Bari (Italy)
"save as" only in a certain folder
Please take into consideration that SavingReport is a static event and you should assign that event only once.
Thank you.
Code: Select all
private void Form1_Load(object sender, EventArgs e)
{
report = new StiReport();
StiDesigner.SavingReport += new StiSavingObjectEventHandler(On_SavingReport);
report.Design();
}
private void On_SavingReport(object sender, StiSavingObjectEventArgs e)
{
StiReport report = (sender as StiDesigner).Report;
SaveFileDialog mySaveDialog = new SaveFileDialog();
mySaveDialog.InitialDirectory = "D:\\";
if (mySaveDialog.ShowDialog() == DialogResult.OK)
{
if (Path.GetDirectoryName(mySaveDialog.FileName) == "D:\\")
{
report.Save(mySaveDialog.FileName);
MessageBox.Show("Saving complete.");
}
else
{
MessageBox.Show("Please choose another folder.");
}
}
}
}
- Fabio Pagano
- Posts: 355
- Joined: Mon Apr 16, 2007 12:38 pm
- Location: Bari (Italy)
"save as" only in a certain folder
Ok: after "report.save" i would add:
otherwise if you do "save as" and change the file name, the report name remains the older.
Any other property to set to make it consistent?
Another question: the event is fired also if the user chooses "save" (not "save as") but in the "save" case i don't want to make appear the save dialog (because i already have all informations). Is there a way to recognize, in this scenario, if the user has done "save" or "save as"?
Thanks.
Code: Select all
report.Designer.ReportFileName = mySaveDialog.FileName
Any other property to set to make it consistent?
Another question: the event is fired also if the user chooses "save" (not "save as") but in the "save" case i don't want to make appear the save dialog (because i already have all informations). Is there a way to recognize, in this scenario, if the user has done "save" or "save as"?
Thanks.
"save as" only in a certain folder
The event handler looks like that:Fabio wrote:Ok: after "report.save" i would add:
otherwise if you do "save as" and change the file name, the report name remains the older.Code: Select all
report.Designer.ReportFileName = mySaveDialog.FileName
Any other property to set to make it consistent?
Another question: the event is fired also if the user chooses "save" (not "save as") but in the "save" case i don't want to make appear the save dialog (because i already have all informations). Is there a way to recognize, in this scenario, if the user has done "save" or "save as"?
Thanks.
Code: Select all
private void On_SavingReport(object sender, StiSavingObjectEventArgs e)
Code: Select all
e.SaveAs
Thank you.