Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# SaveFileDialog in specific folder

I use SaveFileDialog to select the path where I want to save a file. I set InitialDirectory to some folder, but I want to limit the save locations to that folder or subfolders of that folder. Is this possible?

SaveFileDialog dialog = new SaveFileDialog();
dialog.InitialDirectory = "SomePath"//this is the path that I want to be root folder
like image 735
Mircea Ispas Avatar asked Jan 09 '12 13:01

Mircea Ispas


1 Answers

No it is not possible.

You can't directly set this as a Property on the SaveFileDialog. But you can try to do it by using the FileOk event to validate if the file is in that directory and otherwise cancel the event!

dialog.FileOk +=
    delegate (object sender, CancelEventArgs e)
    {
        if (dialog.FileName is in wrong directory)
        {
            e.Cancel = true;
        }
    };

As mentioned, the next best option is to build your own Dialog!

like image 147
Kolky Avatar answered Sep 29 '22 14:09

Kolky