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
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

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
 
 
25 Inspiring Game of Thrones Quotes
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
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer