AlwaysAProgrammer
AlwaysAProgrammer

Reputation: 2919

convert %SystemDrive% to drive letter

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?

Upvotes: 10

Views: 5391

Answers (1)

PSL
PSL

Reputation: 123739

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");

Upvotes: 21

Related Questions