C # environment variables

I used an environment variable that was named ABC and had the value C: / ABC.
In my code, I used @% ABC% / file.txt for the path to the file where I created a folder on drive C with the name ABC containing the file.txt file.

However, this does not recognize the environment variable.

Is there a way to do this short work, or do I need to manually read the System Environment variable in a separate environment variable using the Environment.GetEnvironmentVariable Method (String) in Visual Studio?

+4
source share
5 answers

You can do it:

 string path = Environment.ExpandEnvironmentVariables(@"%ABC%/file.txt"); 

http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx

+3
source

There is aptly named Environment.ExpandEnvironmentVariables that should do the job for you.

+2
source

Use Environment.ExpandEnvironmentVariables :

 string expanded = Enviroment.ExpandEnvironmentVariables(input); 
+2
source

use the System.Environment class .

 System.Environment.ExpandEnvironmentVariables("") 
+1
source

Try

  string _yourpath = Environment.ExpandEnvironmentVariables(@"%ABC%/file.txt"); 
+1
source

Source: https://habr.com/ru/post/1497763/


All Articles