4
 System.Windows.Forms.FolderBrowserDialog dlg = new FolderBrowserDialog();
 HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
 System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);
 System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);

I have used this to get the folder dialog box but now i need to disable right click in that folder dialog box, so that i can prevent deletion of folders from there..enter code here

Creating a custom folderDialog box is the last option i want to take..

So, Could some one suggest any possible solution for this without custom folderDialog.

Ravindra Nadh
  • 131
  • 2
  • 10

2 Answers2

2

You can't. The class cannot be inherited so you can't override any of the settings. There are no events to hook into.

So you have a couple options:

  1. Roll Your Own
  2. Use the file system to lock down your user environment.
  3. Buy a third party control that has this functionality.

We opted for option 2, because the end users did not need to use "normal" windows apps/file locations on our RDP server, they just needed to run our application. The Organizational Unit (OU) they are added to applies permissions that they only had access to the folders we wanted them to have access to. They can't see any of the normal items you would see when the dialog is shown, but can create folders, save items, load items from the folders we give them permission to use.

Rob Stewart
  • 441
  • 4
  • 14
0

Ravindra,

Since Delete in the ContextMenu is a windows feature, you would have to modify the registry settings.

In essence you have to modify/delete the Delete registry entry & after your code executes you must restore it.

You can find the registry entry under: HKEY_CLASSES_ROOT. (You would indeed take some time to figure out this entry).

Ex:

  System.Windows.Forms.FolderBrowserDialog fd = new System.Windows.Forms.FolderBrowserDialog();

  //Get key for New menu option in Context menu.
  RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Directory\Background\shellex\ContextMenuHandlers\New",true);

  //Set it to blank.
  key.SetValue("", "");
  fd.ShowDialog();

  //Restore the value.
  key.SetValue("", "{D969A300-E7FF-11d0-A93B-00A0C90F2719}");`
Ankit
  • 672
  • 6
  • 18