Zoltán Tamási
Zoltán Tamási

Reputation: 12789

How to hide features and selectable folders/drives on an OpenFileDialog window?

I'm currently working on a software for an embedded device running WES7. The application is a standard, .NET 3.5 WinForms project.

The requirement is that users should be able to browse and select specific files from their pendrive, or from network, but not from any locations on system drive. So I'm looking for a solution to hide the links and buttons on the standard OpenFileDialog window somehow, so the users would see only their pendrives if there is any, or network places link.

I was searching already on MSDN and on other forums as well, and I couldn't find any idea until now. If there is no way to get this work with the standard OpenFileDialog, are there any simple custom components out there for browsing files restricted to specified drives or parent folders?

Upvotes: 5

Views: 3163

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65672

Here you go, its as easy as Customizing Your Open File Dialog

The OpenFileDialog class exposes a set of properties to configure the dialog. For example, you can choose the initial directory, the initial filter index, the title of the window, whether multiple files can be selected, and whether the application's current directory should be restored before closing. The class also fires an event (called FileOk) whenever the user clicks on the Open button.

OpenFileDialog is a sealed class, so you can't derive from it. However, if you want to customize the behavior of a file dialog, to the extent that it is possible, you should create a brand new class deriving from the abstract class FileDialog. In this case, you have access to a couple of powerful but protected methods such as HookProc and RunDialog. HookProc defines the dialog box hook procedure that adds specific functionality to the common dialog....

Update:

On Windows 7 PC's it doesn't work. eg:

OpenDialogPlaces o = new OpenDialogPlaces();
//o.Places.Add(18);
//o.Places.Add(5);
//o.Places.Add(6);
o.Init();
o.OpenDialog.ShowDialog();
o.Reset();

Still shows everything in the left-hand:

enter image description here

It did work in previous versions of Windows:

enter image description here

Another thing it appears Microsoft has changed the ComDlg32's location, I tried both places but no luck.

enter image description here

Upvotes: 1

Related Questions