.NET allows me to create and access values that are persistent between sessions.
Is it possible to use environment variables such as %WINDIR%
, %APPDATA%
and others?
If so, how would I go about doing this?
Asked
Active
Viewed 3,493 times
1

Sk93
- 3,676
- 3
- 37
- 67
-
Are you talking about [Environment Variables](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx) ? if so then see [How do I get and set Environment variables in C#?](http://stackoverflow.com/questions/185208/how-do-i-get-and-set-environment-variables-in-c) – Habib May 24 '13 at 07:17
1 Answers
3
If you have this in the config:
<appSettings>
<add key="SomePath" value="%TEMP%"/>
</appSettings>
Then from code you'd do something like:
string path = ConfigurationManager.AppSettings["SomePath"];
string fullPath = System.Environment.ExpandEnvironmentVariables(path);

Dimitar Dimitrov
- 14,868
- 8
- 51
- 79
-
So, this would change the path `%TEMP%/foobar` into `C:/Windows/Temp/foobar/`, right? – May 24 '13 at 07:51
-
1