Page 1 of 1

"save as" only in a certain folder

Posted: Wed Apr 25, 2007 6:16 pm
by Fabio Pagano
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

Posted: Thu Apr 26, 2007 2:16 am
by Edward
Please take into consideration that SavingReport is a static event and you should assign that event only once.

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.");
                }
            }
        }
    }
Thank you.

"save as" only in a certain folder

Posted: Thu Apr 26, 2007 6:17 pm
by Fabio Pagano
Ok: after "report.save" i would add:

Code: Select all

report.Designer.ReportFileName = mySaveDialog.FileName
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.

"save as" only in a certain folder

Posted: Fri Apr 27, 2007 10:10 am
by Edward
Fabio wrote:Ok: after "report.save" i would add:

Code: Select all

report.Designer.ReportFileName = mySaveDialog.FileName
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.
The event handler looks like that:

Code: Select all

private void On_SavingReport(object sender, StiSavingObjectEventArgs e)
This event is called as for the save button as well for the save as button. You can determine that inside the event handler via

Code: Select all

e.SaveAs
property. If true then the Save As was called, otherwise, Save method was called.

Thank you.