Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use system\environment variables in .NET string?

I have path variable which I got from my appsettings:

var path="%TEMP%\myapplication\data";

I am trying to use it in Directory.CreateDirectory(path) method. But I got new folder in my application bin folder instead of C:\Users\Evgeny\AppData\Local\Temp\myapplication\data.

Should I replace %TEMP% manually?

like image 243
Ievgen Avatar asked Mar 20 '13 22:03

Ievgen


1 Answers

Use System.Environment.ExpandEnvironmentVariables like so:

String concretePath = Environment.ExpandEnvironmentVariables(@"%TEMP%\myapplication\data");
like image 153
Dai Avatar answered Oct 26 '22 21:10

Dai