"save as" only in a certain folder

Stimulsoft Reports.NET discussion
Post Reply
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"save as" only in a certain folder

Post 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.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"save as" only in a certain folder

Post 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.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

"save as" only in a certain folder

Post 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.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

"save as" only in a certain folder

Post 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.
Post Reply