I'd like to able to set a path in the config file for my C# 4.0 assembly.
It's likely that the path will be to one of the windows special folders (CommonApplicationData). However in my code I don't want to assume that there will be a special folder in that path, I'd just like an easy/straight-forward way to expand it if there is.
The Path class static method GetFullPath doesn't pick up on an Environment.SpecialFolder enum in a string path (I know this was a big ask, but I did hope)
So I went looking at Environment.ExpandEnvironmentVariables and this led me to the CSIDL and KNOWNFOLDERID
We're still running on XP and adding support for Widnows 7 (I don't think we support Vista)
So I suppose I could put %CSIDL_COMMON_APPDATA% in the path in my config file and use ExpandEnvironmentVariable(), assuming I'm not installing to Windows 7 in which case I assume my installer needs to update config files to use "FOLDERID_ProgramData".
Is this the way I should be dealing with this issue?
Is there a best practice for this that I've missed?
1. How should I represent a windows special folder in a path string in a config file?
2. How do I expand this representation into a full path in my code?
Any advice is welcome, thanks.
Judging by JSOPs response this is probably just wishful thinking but I thought I'd clarify what exactly I'm trying to achieve:
I understand the Environment.SpecifalFolder enum and how to use the Environment.GetFolderPath method, I can even convert a string representation of a special folder to a path:
I'm trying to avoid breaking my path into 2 parts in the config and dealing with a 'SpecialFolder' part separately, because we may not actually use a special folder.
I'd like to be able to configure my path as:
"C:\Documents and Settings\All User\Application Data\MyCompanyName\MyAppName\MyFolder"
But i'd rather not explicitly expand the special folder in the configuration file.
I'd like to be able to enter:
or where we're not using a special folder, enter just:
And I'm asking if there's a library method that will allow me to expand the % wrapped bits in the path automatically, (and that will not fall over if there are no % warpped bits)?
I'm guessing from JSOPs earlier reply that there is not.