Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert %SystemDrive% to drive letter

Tags:

c#

asp.net

c#-4.0

I am using the Web Deploy API to deploy a web site programatically . Before the Deploy, I take a back up of the files. I get the physical path of the files by using the 'ServerManager' Class.

The issue is the physical path returned is %SystemDrive%\Inetpub\wwwroot\<MyApp>.

How do I convert this to a fully qualified path so that I can back it up?

like image 250
AlwaysAProgrammer Avatar asked Apr 30 '13 00:04

AlwaysAProgrammer


1 Answers

One way you can get it is by using:-

var actualPath = Environment.ExpandEnvironmentVariables(yourpathtoconvert);

ex:- var actualPath = Environment.ExpandEnvironmentVariables(@"%SystemDrive%\Inetpub\wwwroot\");

Reference

This will help you convert any of the environment variables to its actual values as configured in the Operating System.

Another way probably is less helpful as you would need to extract them out and use

Environment.GetEnvironmentVariable("ExactEnvVariableName");

ex:- Environment.GetEnvironmentVariable("SystemDrive");

like image 153
PSL Avatar answered Oct 14 '22 22:10

PSL