Pergunta

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

Foi útil?

Solução

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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top