0

I want to avoid opening the Save As dialog in one specific folder. If I open a file from that folder then do a Save As…, it starts in that same folder (as expected). I thought I could just examine InitialDirectory after calling new SaveFileDialog() and change it if necessary, but it is an empty string.

Directory.GetCurrentDirectory() returns the folder containing the executable.

var dialog = new SaveFileDialog();
Console.WriteLine(Directory.GetCurrentDirectory()); // Prints "Z:\Documents\Projects\ProjectName\bin\x64\Debug"
Console.WriteLine(dialog.InitialDirectory); // Prints empty string

How do I ask Windows (7 or 10) which folder the Save As… dialog will start in?

Edit

This is a completely different question than "How do I set the initial directory?". I want to know what the initial directory is going to be before the dialog opens so that I can change it only in the case where it is going to be one specific directory.

SSteve
  • 10,550
  • 5
  • 46
  • 72
  • have you checked this : https://stackoverflow.com/questions/1175242/setting-the-initial-directory-of-an-savefiledialog – Ehsan Sajjad Jun 15 '17 at 23:42
  • The initial directory is stored on an application basis somewhere. Not in plaintext in the registry anyway, as far as a quick test showed. `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU` contains some fragments. `FileDialog.InitialDirectory` doesn't get seeded with it anyway, it appears to be determined _after_ you call `ShowDialog()`. – CodeCaster Jun 16 '17 at 12:38
  • @CodeCaster Thanks. That got me close enough that I was able to find the answer with some searching. The most recent directory is in `LastVisitedPidlMRU`. Interpreting that data is a different issue. – SSteve Jun 16 '17 at 19:22

1 Answers1

-1

I assume that you want the savefiledialog to start from the folder you want

Try this to change the initial directory to whatever you want

dialog.InitialDirectory="C:\Users\Your_Name\Desktop\";
Amine Messaoudi
  • 2,141
  • 2
  • 20
  • 37