Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

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

3/4/2011 8:49:37 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server