Logo
Lose Weight
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Azure

The basics of BLOBs : Developing against containers (part 2) - Creating a container

3/4/2011 8:49:37 AM

3. Creating a container

Now you’re going to create the web page shown in figure 1. In your podcast sample web role project, create a new ASPX page called containers.aspx.

At this stage, you only want to write the code that will create your container; you don’t need to see the list of containers. At present, your UI needs to display only the new container name text box and the Create Container button.

The following listing shows the ASPX required for the create-container section of the page.

Listing 1. ASPX for creating a container

You’ve defined your UI. Now you need to create the code that handles the button click. See the following listing, which contains the code-behind for the create button click event.

Listing 2. Creating a new container

Before we explain this code, we want to remind you of its purpose. The user will type in the new container name and then click the button to create the new container. Now let’s look at the code.

Storage Account

The first thing you need to do is retrieve an object that allows you to work with the BLOB storage account. Using the CloudStorageAccount object that you used earlier to extract your credentials, you can now instantiate a CloudBlobClient object that will allow you to mess with things at an account level by issuing the following call:

CloudBlobClient blobClient =
account.CreateCloudBlobClient();

After you’ve retrieved the CloudBlobClient object, you can perform the following operations at an account level on BLOB storage:

  • Return a list of all containers in the account (ListContainers)

  • Get a specific container (GetContainerReference)

  • List BLOBs (ListBlobsWithPrefix)

  • Get a specific BLOB (GetBlobReference)

As well as performing these operations, you can also set some general policies, including the following ones:

  • Block sizes

  • Retry policy

  • Timeout

  • Number of parallel threads

In this example, because you’re creating a new container, you need to grab a reference to the container that you want to create. Use the GetContainerReference method, passing in the name of your new container:

CloudBlobContainer container =
blobClient.GetContainerReference(txtContainerName.Text.ToLower());

In this example, you’re setting the container name to whatever the user types in the text box.

Note

The name of the container is converted to lowercase because the BLOB storage service doesn’t allow uppercase characters in the container name.


So far you’ve just set up the container you want to create; you haven’t made any communication with the storage service. The CloudBlobContainer object that has been returned by GetContainerReference can perform the following operations:

  • Create a container (Create)

  • Delete a container (Delete)

  • Get and set any custom metadata you want to associate with the container

  • Get properties associated with the container (for example, ETag and last modified time)

  • Get and set container permissions

  • List BLOBs (ListBlobs)

  • Get a specific BLOB

Now make a call to create the container:

container.Create();

As soon as you call the Create method, the storage client generates an HTTP request to the BLOB storage service, requesting that the container be created.

Default permissions

In the Create container call, you didn’t specify any permissions on the container to be created. By default, a container is created as private access only, meaning that only the account owner can access the container or any of the BLOBs contained within it. In the next chapter, we’ll look at how you can set permissions on containers and BLOBs.


You should now be able to run your web role and create some containers in your development storage account. At this point, you won’t be able to see the containers that you’ve created in your web page, but you can check that they’re there by running a SQL query against the BlobContainer table in the development storage database.

Now that you can create a container from your web page, you need to modify the page so that you can display all the containers in your storage account.

Other -----------------
- The basics of BLOBs : Developing against containers (part 1) - Accessing the StorageClient library & Accessing development storage
- The basics of BLOBs : Getting started with development storage
- A closer look at the BLOB storage service
- Storing files in a scaled-out fashion is a pain in the NAS (part 2) - The BLOB service approach to file management
- Storing files in a scaled-out fashion is a pain in the NAS (part 1) - Traditional approaches to BLOB management
 
 
Most view of day
- Understanding Network Services and Active Directory Domain Controller Placement for Exchange Server 2013 (part 7)
- Understanding Network Services and Active Directory Domain Controller Placement for Exchange Server 2007 : Domain Name System and Its Role in Exchange Server 2007
- Windows Server 2012 : Configuring IPv6/IPv4 interoperability (part 3) - IPv6 address representation
- SharePoint 2010 : Connecting and Disconnecting Servers with Windows PowerShell, Additional Functionality in SharePoint 2010
- Microsoft Exchange Server 2013 : Creating new mailboxes (part 1)
- Microsoft Dynamic AX 2009 : .NET Business Connector - Introduction
- Microsoft Project 2010 : Linking Tasks (part 6) - Creating Links by Using the Entry Table
- Maintaining Desktop Health : Using Task Scheduler (part 2) - Task Scheduler Security, Task Scheduler User Interface
- Client Access to Exchange Server 2007 : Using Outlook 2007 Collaboratively (part 2) - Sharing Information with Users Outside the Company
- Understanding Network Services and Active Directory Domain Controller Placement for Exchange Server 2013 (part 9)
Top 10
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
- MDT's Client Wizard : Application Properties
- MDT's Client Wizard : Operating System Properties
- MDT's Client Wizard : Customizing the Deployment Share
- Windows Server 2012 : Software and User Account Control Administration (part 5) - Maintaining application integrity - Configuring run levels
- Windows Server 2012 : Software and User Account Control Administration (part 4) - Maintaining application integrity - Application access tokens
- Windows Server 2012 : Software and User Account Control Administration (part 3) - Mastering User Account Control - Configuring UAC and Admin Approval Mode
- Windows Server 2012 : Software and User Account Control Administration (part 2) - Mastering User Account Control - Elevation, prompts, and the secure desktop
- Windows Server 2012 : Software and User Account Control Administration (part 1) - Software installation essentials
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro