Click here to Skip to main content
Click here to Skip to main content

Getting Your Physical Application Path in Window Azure

cloud
Some applications access files from a relative path in the hosted application directory. For example, you might want to launch an executable or open a file (such as in my example later in this article when I load an X.509 certificate). To achieve this, you must access the physical application path or file system path. This path is made available through the environment variable RoleRoot.
 
RoleRoot returns different results when you run in the development fabric versus when it's deployed to Azure (the cloud). Running in the development fabric returns a path such as this one for a worker role project:
 
D:\Solution\CloudProject\bin\Debug\CloudProject.csx\roles\RoleProject
When running in the cloud you get
E: Drive PAth
 
In either case, you want to append “approot” to the end of the path, and from there, your deployed files follow your application structure. If you have subdirectories with files or a \bin directory for typical ASP.NET deployments, they are all relative to approot. Note that there isn't a “\” after the drive letter in the cloud, so you need code like the following example to produce a proper approot path:
 
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
 
appRoot = Path.Combine(appRoot + @"\", @"approot\");
 
To produce a file path, use this code:
 
string privateKeyCert = "busta-rp.com.pfx";
 
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
 
string pathToPrivateKey = Path.Combine(appRoot + @"\", string.Format(@"approot\{0}", privateKeyCert));
 
This code will work for either development or cloud deployments, so you don't have to adjust your code when you deploy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

maq_rohit a.k.a asthanarht
Technical Lead
United States United States
Rohit is a Lead Engineer from NCR. He started Embedded Programing in his college days and now he is a Software Developer by Profession. Mainly he interested in cutting edge technology offer by Microsoft (i.e Azure,MVC). He Loves coding and his passion is always been towards Microsoft Technologies. Apart from coding his other hobbies include reading books and hang out with friends is his most favorite past time hobby.
 

1. 20 Apr 2014: Best Mobile Article of March 2014 - First Prize
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 19 Dec 2010
Article Copyright 2010 by maq_rohit a.k.a asthanarht
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid