In this article, we are trying to experiment the local
storage feature of Windows Azure. From
the previous article we found that local storage is one of the primitive
storage mechanisms in Windows Azure.
The core features of Local Storage are:
provided by the Operating System
to Hard Drive
as logical file system
Directory/File IO Framework used to access it
be used for storing Cache items
Creating a Local
Here we are creating a local resource through the step by
Step1: Create new
Web Role project
You will be familiar with web role creation and you can
repeat the same. After the solution is
created, the Solution Explorer will be looking like below:
Step 2: Open the
local storage pane
Now double click on the WebRole1
item shown above to open the project configuration, Form there click the Local Storage pane item.
Step 3: Add a new
Local Storage item
Add a new local storage items by clicking the Add Local Storage button. Rename it to TestStorage Change the Size to 10 MB as shown in the figure and
save the configuration.
The above change will modify the configuration file of the
Step 4: Show Information about the Local Resource
Now we can place a label on the page, rename it to InfoLabel.
Then on the page load event we can access the local resource and
show the properties it has.
property gives the current path of the resource in machine.
property returns the size allocated to it.
On executing the application we can see the following
Step 5: Start
using the folder
Now we can use the above folder for our storage
purpose. We can create folder, files
Create a new button on the page and name it as CreateFolderAndFileButton. On click of the button place the code to
create a directory and file.
protected void CreateFolderAndFileButton_Click(object sender, EventArgs e)
LocalResource resource = RoleEnvironment.GetLocalResource("TestStorage");
File.Create(resource.RootPath + "\\NewFile.txt");
private void ShowContents(string path)
InfoLabel.Text = "Directories inside it:
foreach (string dir in Directory.GetDirectories(path))
+= dir + "
InfoLabel.Text += "
Files inside it";
foreach (string file in Directory.GetFiles(path))
InfoLabel.Text += file + "
Execute the application and on clicking the button we can
see the following output.
In this article we have found how to use the local storage
feature of Windows Azure and creating folder and file inside it.