Why does FileDialog sometimes not remember the start directory?

I created a WPF application where you can open some Open / SaveFileDialogs. On my PC, it remembers the directory that I was last in, I used such a dialog box and sets it as the initial directory when opening another such dialog. But on my colleague, he does not remember the PC.

The exact class I'm using is Microsoft.Win32.OpenFileDialog . We both installed WinXP.

What could be the reason for this?

UPDATE: Apparently, this problem has not yet been resolved. I found out that this also happens on my PC. I found that when I select several files and open a click or press the enter key, it does not save the place where it was. But when I select only one file and the watch opens or presses the enter key (or double-clicks on it), then it remembers the location.

Here is the code:

 public override void Execute(object parameter) { OpenFileDialog dialog = new OpenFileDialog(); dialog.DefaultExt = ".txt"; dialog.Filter = "Text files (.txt)|*.txt"; dialog.Multiselect = true; dialog.Title = "Select a trace file"; // The documentation says ShowDialog always returns either true or false, // so we get the value of the returned Nullable<bool> immediately to get // rid of the Nullable<bool> type. bool result = dialog.ShowDialog().Value; if (result) { foreach (string fileName in dialog.FileNames) { traceFilesViewModel.TraceFileList.Add(fileName); traceFilesViewModel.StatusBackground = Brushes.PeachPuff; traceFilesViewModel.StatusForeground = Brushes.Red; traceFilesViewModel.StatusText = "Trace files not loaded."; } } } 
+4
source share
2 answers

Something that can make OpenFileDialog "forget" the last directory used:

  • folder has been moved / renamed
  • the user does not have permissions to read the folder anymore
  • the system disk (containing user profiles) is full and the user profile cannot be saved correctly on the local computer.
  • the application runs from a remote location, and this location is not considered trusted (for example: \ server \ deployment \ myapp.exe)

Hope this helps.

+4
source

If the error still persists, you can use this property to save the initial directory: openFileDialog1.InitialDirectory = "c:\"

Additional Information: MDSN Property FileDialog.InitialDirectory

0
source

Source: https://habr.com/ru/post/1303782/


All Articles