WPF – Prevent file dialog selection from being added to recents
Files opened or saved using WPF’s file dialogs (OpenFileDialog
, SaveFileDialog
or OpenFolderDialog
) are by default added to the Windows Explorer’s recent files list and can also impact the Recommended section of the Start Menu in Windows 11.
To disable this behavior, you can set AddToRecent
to false
on your dialog before calling the ShowDialog()
method. Note: this property has been added part of .NET 8, so in case you don’t have it available, make sure your project is targeting .NET 8 or newer.
And for a very quick example:
var dialog = new OpenFileDialog
{
AddToRecent = false
};
dialog.ShowDialog();
Code language: C# (cs)
That’s it. Now the files picked by the user using the OpenFileDialog
will no longer show in the recent files list or in the start menu.
Note: AddToRecent
has a default value of true
. So unless you explicitly set it to false
, the files picked using the dialogs will show up in the recents.
One Comment