Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict user to a particular directory in OpenFileDialog

Is there any way I can restrict a user to select files from only a particular directory in C#? It should not be allowed to browse other folders.

like image 780
Dark Knight Avatar asked Feb 26 '23 12:02

Dark Knight


1 Answers

Not possible with the standard .NET wrappers. Reject the path with the FileOk event.

If you can count on your program running on Vista and up then you could consider using the CommonFileDialog class in the Windows API Code Pack. It has a FolderChanging event that can be canceled.

like image 170
Hans Passant Avatar answered Mar 07 '23 15:03

Hans Passant