.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> Azure >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Azure Part 16: Create Blob in Storage Emulator

Posted By:Jean Paul       Posted Date: October 31, 2011    Points: 200    Category: Azure    URL: http://www.dotnetspark.com  

Create Blob in Storage Emulator

In this article we are trying to create a blob in the storage emulator.  The same blob creation can be done on storage account too.


Some Theories on Blob in Azure


  • Blob represents Binary Large Object
  • It can contain text and binary data
  • Containers are required for storing Blobs
  • Containers can be private and public
  • Blob can have metadata


The storage account created should be having containers for storing blobs.  The containers can be viewed as folders. 

Eg: Documents, Images etc.


The private containers are private to the storage account and only the account holder can access it.  The urls in public containers are accessible over the internet.


The Blob can have metadata as collection of key value pair.  We can store the information like Author, Date, and Description etc. for the blob.


Advantages of Blob


The blob helps us to store image files, documents etc. which are normally unstructured data.  If the same is stored in database, it results in performance problems. 


Without a blob service, the manual programming requires much effort to manage the large sized files. 


The activities include:


  • Creating a File/Folder infrastructure in the web application space
  • Create with multipart uploads for uploading large files
  • Create a database table for managing the metadata
  • Create the corresponding entities
  • Manage with backup and restore of the large files involving high network traffics


Thanks to Microsoft, the blob service does all the things for us at a lower cost.


Steps in creating Blob


Following are the steps in creating a blob.



The first step (Create Storage Account) was already done from our side and we need to proceed with the further steps to create the blob.


There are two ways of creating container and blob


  • Through Program
  • Using Windows Azure Management Tool


In this article we are proceeding with the first way and the second way will be discussed in another upcoming article.


Following are the steps involved in the creation of container and blob.


Step 1: Create new web azure project


Create a new Windows Azure project and add a web role into it.  The solution explorer would look like below.



Step 2: Add reference to library files


We need to add specific reference to the following Windows Azure SDK dll file.


Dll: Microsoft.WindowsAzure.StorageClient.dll

Location: C:\Program Files\Windows Azure SDK\v1.5\ref




Step 3: Create the container


Now open the code view of Default.aspx, place a label control on it and enter the following code.


protected void Page_Load(object sender, EventArgs e)


  CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount;

  CloudBlobClient client = account.CreateCloudBlobClient();

  CloudBlobContainer container = client.GetContainerReference("documents");



  CloudBlob blob = container.GetBlobReference("File.txt");




  // show the blobs

  Label1.Text = "Blobs inside container:

  foreach (IListBlobItem item in container.ListBlobs())

    Label1.Text += item.Container + " " + item.Parent.ToString() + " " +   

    item.Uri.ToString() + "



Note: The container name as documents.  We need to ensure the name should be lowercase and additional restrictions.  An invalid naming convention will throw exception StorageClientException with message "One of the request inputs is out of range."


There are two methods in class CloudBlobContainer for creating the container.


  • Create()
  • CreateIfNotExist()


Using the CreateIfNotExist() method is advised as it won't throw the exception if a container already exists with the given name.


Step 4: Create the blob file


In the web role project add a file named File.txt with some text contents.  Execute the application and you can see the following result.



Note: The local Storage Emulator  is used in the above code for creating the container and blob.  In the real scenario of uploading to online storage account, we need to modify the line:



as shown below





In this article we have learned some information on blob, container and how to create them programmatically.   The associated source code can be used to test blob creation in your local machine.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend