Conditional Reading of Windows Azure BLOB

Conditional reading of BLOB implies, you want to read BLOB only when BLOB is modified. There are scenarios when you need to read BLOB frequently. In that case to avoid network usage and bandwidth, you may consider reading BLOB only when BLOB has been modified since last read or download. This type of BLOB reading is termed as Conditional BLOB reading.

Usually to read or download BLOB, you create reference of BLOB as below


In above code snippet

  1. ConnectionString is connection string to your storage account.
  2. Containername is name of the public container.
  3. Doc1.docx is name of the BLOB.

If you want to read it without any condition or in other words you want to read the BLOB regardless of whether it has been modified or not then you can read it in byte array as below,


As of now everything is fine for unconditional read but if you want to do Conditional read on the BLOB then you will have to use ,

  • IfNoneMatch
  •  eTag

IfNoneMatch is a static variable of AccessCondition structure. When you download a BLOB you can additionally provide BLOBRequestOptions. Almost all Download functions are overloaded with BlobRequestOptions.


If you don’t specify BLOBRequestOptions then you will perform unconditional read.

To perform conditional read, you need to follow below steps,

Step 1

Save ETag value from the server at time of first reading in a local variable


Step 2

Create instance of BLOBRequestOptions with setting AccessCondition as below,


In above code we are passing locally saved ETag value to IfNoneMatch


Step 3

At time of making second call onward to download BLOB pass Request Option as below,


If BLOB is not modified then you will get into the Exception

At time of downloading BLOB in above code, server will fist check for the ETatg in IfNoneMatch header. If server don’t find new version, it will send HTTP 304 request to the storage library.

For your reference full source code of conditional BLOB reading is as below,

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace ConsoleApplication7
class Program
static void Main(string[] args)

CloudStorageAccount account = CloudStorageAccount.

CloudBlobClient BlobClient = account.CreateCloudBlobClient();

CloudBlobContainer ContainerReference = BlobClient.

CloudBlob BlobReference = ContainerReference.

byte[] DownloadAsByteArray = BlobReference.DownloadByteArray();

var LastReadETag = BlobReference.Properties.ETag;

BlobRequestOptions RequestOption = new BlobRequestOptions
{ AccessCondition = AccessCondition.IfNoneMatch

byte[] DownloadByteArraySecondTimeOnward = BlobReference.

catch (StorageClientException ex)
if (ex.StatusCode == System.Net.HttpStatusCode.NotModified)





In this way you can perform conditional reading on Windows Azure BLOB. I hope this post is useful. Thanks for reading  Smile


If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

One response to “Conditional Reading of Windows Azure BLOB”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at