8.4.4. Listing containers
In the figure 1,
there’s a grid that contains a list of all the containers in the
account. To create that grid, you need to update your asp.net page to
include an ASP.NET GridView component
(you’re going to eventually bind this grid to a list of containers). You
should place the code in the following listing before the code in listing 1 in the containers.aspx page.
Listing 3. Listing BLOBs with a GridView
The code in listing 3 is the ASP.NET markup for figure 8.11.
Notice that you’re allowing the grid to autogenerate all the columns
(except the Delete button and the View hyperlink) based on the
properties of the object bound to the grid. Listing 8.4 shows the code-behind for your web page that gets a list of containers from the account and binds it to the grid.
Listing 4. Binding the grid
One interesting thing you’ll see in the Page_Load method is a call to SetConfigurationSettingPublisher.
We wouldn’t normally put this code here, but it was the easiest place
to put it in the book. When you load configuration in ASP.NET, it looks
in the web.config file by default. If you’re storing your configuration
in the .csdef file, ASP.NET will never find it. By including this line
of code, you’re telling ASP.NET to look in the .cscfg file for the
configuration you’re trying to load. We would normally put this in the Role_OnStart event, or somewhere else where it’ll be run once per role instance as it starts up.
Now you have a web page that will
display all the containers in your storage account. The page also
allows you to create new private containers. To complete your sample,
you just need to implement the delete functionality.
5. Deleting a container
You want to be able to click
the Delete button on a particular row in your web page to delete the
underlying container. For this to happen, you need to hook in your
Delete button. The following listing shows the code-behind for
implementing the delete functionality.
Listing 5. Deleting the container
With
the Delete button code hooked in, you should be able to run your
application and view all the BLOB containers in development storage, add
a container, and then delete it from your web page.
Wow, you’ve done a great
job. You’ve just completed your first Windows Azure BLOB storage
application. All that’s left is to make this baby work against the live
BLOB storage service.