Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenFileDialog / SaveFile Dialog Initial Folder

I've read through these questions and none of the solutions seem to work. I can get it to work to C:\ and work to the Users home folder but not the folder I've setup in documents for the user called 'Workspace Saves' Here are some code snips.

Makes the folder if it doesn't exists. This works fine...

        // Does Workspace Folder Check

        Directory.CreateDirectory(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "/Workspace Saves");

The dialog part. This always opens in the user folder not the sub folder. tried it multiple ways.

        // Opens Dialog Box
        SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        string path = (Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "/Workspace Saves");
        if (Directory.Exists(path))
        {
            saveFileDialog1.InitialDirectory = path;
        }
        else
        {
           saveFileDialog1.InitialDirectory = @"C:\";
        }  
        saveFileDialog1.Filter = "Workspace Data File |*.wsda";
        saveFileDialog1.Title = "Save current Workspace data.";
        saveFileDialog1.ShowDialog();
        if (saveFileDialog1.FileName != "")
        {   
like image 517
Brian Pulaski Avatar asked Feb 22 '26 19:02

Brian Pulaski


1 Answers

Instead of "/Workspace Saves", use "\\Workspace Saves".

like image 111
Yacoub Massad Avatar answered Feb 24 '26 14:02

Yacoub Massad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!