Setting the initial directory of an SaveFileDialog?

前端 未结 14 2154
一个人的身影
一个人的身影 2020-12-01 10:05

I\'d like a SaveFileDialog with the following behavior:

  • The first time you open it, it goes to \"My Documents\".

  • Afterwards, it goes to the

14条回答
  •  庸人自扰
    2020-12-01 11:07

    I have no idea why this works, but I was finally able to get it working for me.

    I found that if I gave the full path, it would not work, but if I put that full path inside of Path.GetFullPath(), then it would work. Looking at the before and after values show them being the same, but it would consistently not work without it, and work with it.

    //does not work
    OpenFileDialog dlgOpen = new OpenFileDialog();
    string initPath = Path.GetTempPath() + @"\FQUL";
    dlgOpen.InitialDirectory = initPath;
    dlgOpen.RestoreDirectory = true;
    
    //works
    OpenFileDialog dlgOpen = new OpenFileDialog();
    string initPath = Path.GetTempPath() + @"\FQUL";
    dlgOpen.InitialDirectory = Path.GetFullPath(initPath);
    dlgOpen.RestoreDirectory = true;
    

提交回复
热议问题