Summary

Windows Azure storage services provide persistent, redundant storage in the cloud. The Windows Azure Storage helper, allows you to easily retrieve and insert data into Blobs and Tables of Windows Azure Storage Services.

For more information on Windows Azure check out this website: http://msdn.microsoft.com/en-us/windowsazure/default.aspx

Getting started in 60 seconds

Download the Windows Azure Storage Helper package and extract its content in the root folder of your WebMatrix site.

Then provide a set of Windows Azure Storage Credentials, by adding the following lines in your _AppStart.cshtml WebMatrix page. You're good to go!

@{
WindowsAzureStorage.AccountName = yourAccountName;
WindowsAzureStorage.AccountKey = yourAccountKey;
} 

Using the Windows Azure Storage Helper with the Table Service

Create Tables and Insert Rows

@{
WindowsAzureStorage.CreateTable("NewSampleTable");

var row1 = WindowsAzureStorage.CreateRow("partition1", "row1");
row1.Name = "John Doe";
WindowsAzureStorage.InsertRow("NewSampleTable", row1);

var row2 = WindowsAzureStorage.CreateRow("partition1", "row2");
row2.Name = "Jessica Anderson";
WindowsAzureStorage.InsertRow("NewSampleTable", row2);
} 

Retrieve Rows in a Table

@{
var rows = WindowsAzureStorage.GetRows("NewSampleTable");
var grid = new WebGrid(rows);
} 

Update Rows in a Table

@{
var row = WindowsAzureStorage.GetRow("NewSampleTable", "partition1", "row1");
row.Name = "Peter Simmons";
WindowsAzureStorage.UpdateRow("NewSampleTable", row);
} 

Delete Rows in a Table

@{
WindowsAzureStorage.DeleteRow("NewSampleTable", "partition1", "row1");
} 

Delete Table

@{
WindowsAzureStorage.DeleteTable("NewSampleTable");
} 

Using the Windows Azure Storage Helper with the Blob Service

List Blob Containers

@{
var containers = WindowsAzureStorage.ListBlobContainers();
} 

Create a New Blob Container

@{
WindowsAzureStorage.CreateBlobContainer(ContainerName);
} 

List of Blobs from Container

@{
var containers = WindowsAzureStorage.ListBlobs("test");
} 

Upload File to a Blob

@{
var uploadedFile = Request.Files[0];
WindowsAzureStorage.UploadBinaryToBlob(BlobAddress, uploadedFile.InputStream);
} 

Delete Container

@{
WindowsAzureStorage.DeleteBlobContainer("test");
} 

Helper Reference

Properties supported by the Windows Azure Storage Helper:
  • static string AccountName
The name of the Windows Azure Storage account.
  • static string AccountKey
The shared key of the Windows Azure Storage account.

List of methods supported by the Windows Azure Storage Helper:
  • static IList< dynamic > GetRows (string tableName, [string whereOptions], [int take])
Retrieves the rows of a table in the storage account.
  • static dynamic GetRow (string tableName, string partitionKey, string rowKey)
Retrieves a single row from a table in the storage account.
  • static bool TableExists (string tableName)
Checks the existence of a table in the storage account.
  • static IList< dynamic > GetTables ()
Retrieves the Tables in the storage account.
  • static dynamic CreateRow (string partitionKey, string rowKey)
Creates a new instance that represents the row of a table.
  • static void CreateTable (string tableName)
Creates a new table in the storage account.
  • static void DeleteTable (string tableName)
Deletes an existing table from the storage account.
  • static void InsertRow (string tableName, dynamic row)
Inserts a new row into a table.
  • static void UpdateRow (string tableName, dynamic row)
Updates an existing row in a table.
  • static void DeleteRow (string tableName, string partitionKey, string rowKey)
Deletes an existing row in a table.
  • static void UploadBinaryToBlob (string blobAddress, Stream stream)
Uploads binary data to a Blob.
  • static void UploadBinaryToBlob (string blobAddress, byte[] content)
Uploads binary data to a Blob.
  • static void UploadBinaryToBlob (string blobAddress, string fileName)
Uploads binary data to a Blob.
  • static void UploadTextToBlob (string blobAddress, string content)
Uploads a string of text to a Blob.
  • static string DownloadBlobAsText (string blobAddress)
Downloads the blob contents as a string of text.
  • static void DownloadBlobAsStream (string blobAddress, Stream stream)
Downloads the blob contents to a stream.
  • static void DownloadBlobToFile (string blobAddress, string fileName)
Downloads the blob contents to a file.
  • static byte[] DownloadBlobAsByteArray (string blobAddress)
Downloads the blob contents as an array of bytes.
  • static void CreateBlobContainer (string containerAddress)
Creates a new blob container in the storage account.
  • static IList< string > ListBlobs (string containerAddress)
Retrieves a list of all the blobs in a blob container.
  • static IList< string > ListBlobContainers ()
Retrieves a list of all the blob containers in the storage account.
  • static void DeleteBlobContainer (string containerAddress)
Deletes an existing blob container from the storage account.
  • static void DeleteBlob (string blobAddress)
Deletes an existing blob.

Note: The current version of the Windows Azure Storage Helper does not support the following features:
*Azure Queues
*Batch operations (Windows Azure Tables)
*Pagination and continuation tokens (Windows Azure Tables)
*Entity group transactions (Windows Azure Tables)
*Manipulating metadata and properties for Blobs and Containers (Azure Blobs)
*Manipulating Containers ACL (Windows Azure Blobs)
*Lease Blob operations (Windows Azure Blobs)
*Snapshot Blob operations (Windows Azure Blobs)
*Copy Blob operations (Windows Azure Blobs)
*Blobs partial updates - Pages and Blocks (Windows Azure Blobs)


Last edited Oct 12, 2010 at 11:52 PM by jsenior, version 19

Comments

No comments yet.