You can ask a file picker dialog to limit itself to files in the file system by passing the FOS_
FORCEÂFILEÂSYSTEM
flag. There is an analogous BIF_
RETURNÂONLYÂFSÂDIRS
flag for the folder picker.
But if you pass this flag, you’ll still see virtual folders in the user interface. Things like Network and My Computer This PC. And if the user picks it, the OK button grays out, which is confusing. Why are these virtual folders showing up when I explicitly asked that they not show up?
Well, that’s not what you asked.
You asked that the user be able to select only file system files or folder. You didn’t ask that non-file-system object be removed from view.
But why are these non-file-system objects shown in the view if the user can’t select them?
Because there might be a file system object inside them.
The shell namespace has two attributes related to the file system. One is SFGAO_
FILEÂSYSTEM
, which means that the item is itself in the file system. The other is SFGAO_
FILEÂSYSÂANCESTOR
which means that the item or its children are in the file system.
If an item has the SFGAO_
FILEÂSYSÂANCESTOR
attribute, then it will show up in the “make sure the user picks an item in the file system” dialogs: Even if the item itself is not a file system item, it may contain a file system item, so the dialog shows the item so the user can navigate into it to find the actual file system item.
The SFGAO_
FILEÂSYSÂANCESTOR
attribute is like a sign that says “This way to the file system.”
If the file and folder picker dialogs showed only file system objects and not also file system ancestors, then your dialog would be pretty blank, seeing as the root items like This PC and Network are themselves not file system items. But if you want to pick something from your D: drive, you’ll probably need to go through This PC to get there.
I also miss My Computer.