Reputation: 936
I was using an environment variable which was named ABC and had a value of C:/ABC.
In my code I used @"%ABC%/file.txt" for the file path where I had created a folder on the C drive called ABC containing a file called file.txt.
However this does not recognise the environment variable.
Is there any way to make this short-cut work or do I need to manually read the System Environment variable into a separate Environment variable using Environment.GetEnvironmentVariable
Method (String) within Visual Studio?
Upvotes: 4
Views: 509
Reputation: 10226
Try
string _yourpath = Environment.ExpandEnvironmentVariables(@"%ABC%/file.txt");
Upvotes: 1
Reputation: 22794
Use Environment.ExpandEnvironmentVariables
:
string expanded = Enviroment.ExpandEnvironmentVariables(input);
Upvotes: 2
Reputation: 5600
use System.Environment class
.
System.Environment.ExpandEnvironmentVariables("")
Upvotes: 1
Reputation: 23087
You can do this:
string path = Environment.ExpandEnvironmentVariables(@"%ABC%/file.txt");
http://msdn.microsoft.com/en-us/library/system.environment.expandenvironmentvariables.aspx
Upvotes: 3
Reputation: 111810
There is an aptly named Environment.ExpandEnvironmentVariables that should do the work for you.
Upvotes: 2