Cloud Blob Container Class

Posted: January 18, 2013 in Live in a Cloudy World, Windows Azure

Continuing on my previous work on the Windows Azure blog posts, I have written this one to make a simple demonstration about how to use the Windows Azure Cloud Blob Container class. This example will contain, how to create the windows azure cloud blob container, set the container permissions, the blob request options, the shared access Signature.

This is an example of the #LiveinaCloudyWorld papers.

private void testcloudcontainerclass()

{

// associating the created accoutn for the existing connection string for the windows azure storage account

var account = CloudStorageAccount.FromConfigurationSetting(“ConnectionString”);

 

//creating a blob client

CloudBlobClient client = account.CreateCloudBlobClient();

 

//the following line will show you how to create a container with the reference name

//make sure to follow the container name rules

CloudBlobContainer container = client.GetContainerReference(“containername”);

 

//these lines will show you how to create a blobrequestoptions to associate it with the container created

BlobRequestOptions options = new BlobRequestOptions();

options.DeleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;

options.UseFlatBlobListing = true;

options.BlobListingDetails = BlobListingDetails.All;

options.RetryPolicy = RetryPolicies.NoRetry();

 

//setting the container permissions

container.SetPermissions(new BlobContainerPermissions()

{

PublicAccess = BlobContainerPublicAccessType.Blob,

}, options);

 

//setting the container shared access signature

container.GetSharedAccessSignature(new SharedAccessPolicy()

{

Permissions = SharedAccessPermissions.Read | SharedAccessPermissions.Write | SharedAccessPermissions.Delete,

SharedAccessExpiryTime = DateTime.Parse(DateTime.Compare(new DateTime(2013,1,1),new DateTime(2013,12,31)).ToString()),

SharedAccessStartTime = DateTime.Now,

});

 

//uploading a blob

container.GetBlobReference(“myblob”).UploadText(“testing”);

}

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s