Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I have an issue with a program I am creating. I need to be able to use a string output from the FolderBrowserDialog.SelectedPath as an Environment.SpecialFolder type, but if the user selects a custom folder inside an obscure location not included in the Environment.SpecialFolder Enum, the OpenFileDialog won't accept the file path and throw an exception.

Is there a way to make a new Enum value for the Environment.SpecialFolder type based upon the path the user selects? Or is there a property I'm missing?
Posted

1 solution

I think there is no anything you are missing. There is no a predefined way to handle file structure the way you want unless you design and implement it by yourself based on one more path names returned by GetFolderPath(Environment.SpecialFolder), probably this method is not designed with intention to be use with browser or other file dialogs. In common practice, each software product has a fixed sub-directory on one or more of these "special folders", perhaps set up in a configuration file, user's options, etc., with no connection to file dialogs.

If you really need what you want (I advise you critically review this idea, but it might has its merits), and if you really want a high-quality solution, I would suggest you develop your own class(es) implementing file dialog(s) the way it could be initialized with some top level directory, so the dialog operations would never navigate outside of it.

Throwing and handling exception and showing it to the user in response to user's "wrong" decision in cases when it is not absolutely necessarily is called user brainwashing, a bad UI practice.

—SA
 
Share this answer
 
v3
Comments
Wonde Tadesse 7-Dec-11 18:55pm    
5+
Sergey Alexandrovich Kryukov 7-Dec-11 19:02pm    
Thank you, Wonde.
--SA
EpikYummeh 8-Dec-11 16:24pm    
That is a very good idea, but what if the user selects the following example file path:
C:\My Documents\Summer Camp Pictures\2007-07-24\

That is only one example. I tend to organize my images, but I think the main solution could be just only allowing users to open from the main available Environment.SpecialFolder locations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900