Search code examples
c#visual-studio-2010savefiledialogfileopendialog

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 != "")
        {   

Solution

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