Convert% SystemDrive% to drive letter

I am using the Web Deploy API to deploy a website programmatically. Before deploying, I take a backup of the files. I get the physical file path using the class 'ServerManager' .

The problem is returning the physical path %SystemDrive%\Inetpub\wwwroot\<MyApp> .

How do I convert this to the full path so that I can support it?

+8
source share
1 answer

One way to get it is: -

 var actualPath = Environment.ExpandEnvironmentVariables(yourpathtoconvert); 

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

Link

This will help you convert any of the environment variables into its actual values ​​as they are configured in the operating system.

Another way is probably less useful, since you will need to extract them and use

 Environment.GetEnvironmentVariable("ExactEnvVariableName"); 

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

+16
source share

All Articles