Вопрос

.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?

Это было полезно?

Решение

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top