tags:

views:

47

answers:

2

Hi all

How to create a sub container in the azure storage location.

Please let us know

A: 

Are you referring to blob storage? If so, the hierarchy is simply StorageAccount/Container/BlobName. There are no nested containers.

Having said that, you can use slashes in your blob name to simulate nested containers in the URI. See this article on MSDN for naming details.

David Makogon
+1  A: 

Windows Azure doesn't provide the concept of heirarchical containers, but it does provide a mechanism to traverse heirarchy by convention and API. All containers are stored at the same level. You can gain simliar functionality by using naming conventions for your blob names.

For instance, you may create a container named "content" and create blobs with the following names in that container:

themes/blue/images/logo.jpg
themes/blue/images/icon-start.jpg
themes/blue/images/icon-stop.jpg

themes/red/images/logo.jpg
themes/red/images/icon-start.jpg
themes/red/images/icon-stop.jpg

Note that these blobs are a flat list against your "content" container. That said, using the "/" as a conventional delimiter, provides you with the functionality to traverse these in a heirarchical fashion.

protected IEnumerable<IListBlobItem> 
          GetDirectoryList(string directoryName, string subDirectoryName)
{
    CloudStorageAccount account =
        CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    CloudBlobClient client = 
        account.CreateCloudBlobClient();
    CloudBlobDirectory directory = 
        cloudBlobClient.GetBlobDirectoryReference(directoryName); 
    CloudBlobDirectory subDirectory = 
        directory.GetSubdirectory(subDirectoryName); 

    return subDirectory.ListBlobs();
}

You can then call this as follows:

GetDirectoryList("content/blue", "images")

Note the use of GetBlobDirectoryReference and GetSubDirectory methods and the CloudBlobDirectory type instead of CloudBlobContainer. These provide the traversal functionality you are likely looking for.

This should help you get started. Let me know if this doesn't answer your question:

[ Thanks to Neil Mackenzie for inspiration ]

tobint