Category: Azure

Temporary File Storage for Azure Web Role

First, make sure that you design for cloud operating system, this way your application will not require to write to some specific file path or directory etc. But there will be instances where you will need to write or save a file in a local path somewhere. Azure helps us to do this by means of “LocalResource”

To set this up, its simple, open your ServiceDefinition.csdef file,
Add under section,

<WebRole name="MyWebRole" vmsize="Small">
       <LocalStorage name="MyLocalStorage" sizeInMB="10" />

One you have this, your role environment will get you a local resource when its running, (even when using an emulator on local)

Now you are ready to use local file system on Azure, here is how you access:

if (RoleEnvironment.IsAvailable) // this guard helps not to throw error when running outside emulator in local
LocalResource localResource = RoleEnvironment.GetLocalResource("MyLocalStorage");
Debug.WriteLine (localResource.RootPath);


Windows Azure Training Kit