How to disable "Network" in Explorer via registry key?

126 views Asked by At

I am trying to disable/hide the "Network" folder when calling the SaveFileDialog in C# WPF and from everything that I've read on SO/Google, there is no way to customize/hide/disable the Navigation Pane at all.

enter image description here

However, I've stumble upon an option in "Folder Options > Show Network", which allows me to hide the "Network" link in the Navigation Pane. Does anyone know which registry key I need to use to toggle it? My plan is to programmatically set the flag to 0 before I show the dialog and restore it back to its original state when I finish.

enter image description here

I've dig through the following resources (and more) but can't find what I need:

The reason to hide the Network shortcut is because under VPN environment accessing the "Network" would cause the C# app to crash.

1

There are 1 answers

0
codenamezero On

After digging for a few more hours, I've actually found 2 alternatives.

Solution 1 - Hiding Navigation Panel

There are 2 ways to hide the navigation panel

  • 1a) Install the NuGet WindowsAPICodePack and set the ShowPlacesList to false OR
  • 1b) Create your own FileDialogNative interop file and HIDEPINNEDPLACES by using the SetOptions

Example 1a:

 using Microsoft.WindowsAPICodePack.Dialogs;

 var dialog = new CommonOpenFileDialog()
 {
     ShowPlacesList = false
 };

Example 1b, requires you take a copy of this file, which allows you to have access to IFileDialog, and put it in your project:

var dialog = (FileDialogNative.IFileSaveDialog) new FileDialogNative.FileSaveDialogRCW();
dialog.SetOptions(FileDialogNative.FOS.FOS_HIDEPINNEDPLACES);
dialog.Show(new WindowInteropHelper(Application.Current.MainWindow).Handle);

Using either one of the above implementations will hide the entire navigation panel. However, note that the user CAN STILL navigate away through the address bar within the dialog... so this isn't really a perfect solution, at least not for me, but perhaps it is for somebody else.

Solution 2 - Handling FolderChanging event

Although it feels a bit "hacky", this actually solved my original problem. You still need to install the NuGet WindowsAPICodePack but you no longer need to hide anything from the file dialog and just use it as-is.

using Microsoft.WindowsAPICodePack.Dialogs;

var dialog = new CommonOpenFileDialog()
dialog.FolderChanging += (sender, e) =>
{
    Log.Debug("FolderChanging");
    e.Cancel = true;
};

And you could check for the actual path/folder/item being selected, in the screenshot below, it shows when the "Network" shortcut was being clicked, and by setting Cancel to true we can ignores the selection.

Hope this helps someone.

enter image description here