0

I have written an app using WPF in C#.

When the InitialDirectory property of the OpenFileDialog instance is empty, I want to know which directory opens when ShowDialog() is performed.

It seems that the directory in which the file was last opened is stored in the registry for each application, and that directory is opened.

But I haven't found a way to verify that.

I am confident that the registry mentioned below contains the required data.

...\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU

I used livet OpenFileDialogInteractionMessageAction class InvokeAction() method https://github.com/runceel/Livet

public class OpenFileDialogInteractionMessageAction : InteractionMessageAction<DependencyObject>
    {
        protected override void InvokeAction(InteractionMessage message)
        {
            // ReSharper disable once InvertIf
            if (message is OpeningFileSelectionMessage openFileMessage)
            {
                var dialog = new OpenFileDialog
                {
                    FileName = openFileMessage.FileName,
                    InitialDirectory = openFileMessage.InitialDirectory,
                    AddExtension = openFileMessage.AddExtension,
                    Filter = openFileMessage.Filter,
                    Title = openFileMessage.Title,
                    Multiselect = openFileMessage.MultiSelect,
                    RestoreDirectory =true,
                };

                var showDialog = dialog.ShowDialog() ?? false;
                openFileMessage.Response = showDialog ? dialog.FileNames : null;
            }
        }
    }

OpenFileDialog default path This question was very helpful.

But, in the official docs, I didn't find any mention of it being stored in that registry. I would like to know the location of the official documentation. Or I would like to see evidence (code etc...) of using the path stored in that registry.

MaggieIto
  • 1
  • 2
  • https://stackoverflow.com/questions/9980262/openfiledialog-default-path I am going to read Chipset31's comment for URL mentioned above carefully. I noticed that Chipset31 mentions how to get the value stored in the registry. – MaggieIto Oct 10 '22 at 14:50

0 Answers0