Click here to Skip to main content
13,448,076 members (56,430 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 2 Dec 2010

Getting Your Physical Application Path in Window Azure

, 19 Dec 2010
Rate this:
Please Sign up or sign in to vote.
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:


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

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.


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


About the Author

Technical Lead
United States United States
Rohit 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

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180318.3 | Last Updated 19 Dec 2010
Article Copyright 2010 by maq_rohit
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid