Windows Azure storage tables – How to delete a table in C#

Namespace declarations

Add the following code namespace declarations to the top of any C# file in which you wish to programmatically access Azure Storage.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;

 try
            {
                // Retrieve the storage account from the connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                        ConfigurationManager.AppSettings["StorageConnectionString"]);

                // Create the table client.
                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                // Create the table if it doesn't exist.
                //Table names must be unique within an account.
                //Table names may contain only alphanumeric characters.
                //Table names cannot begin with a numeric character.
                //Table names are case-insensitive.
                //Table names must be from 3 to 63 characters long.
                //Some table names are reserved, including "tables". Attempting to create a table with a reserved table name returns error code 404 (Bad Request)..
                string strTableName = txtClientDB.Text.Trim().Replace("_", "") + "erp";
                strTableName = strTableName.ToLower();
                CloudTable table = tableClient.GetTableReference(strTableName);
                // Delete the table it if exists.
                table.DeleteIfExists();
                lblSuccess.Text = "Delete succeeded";
                lblSuccess.Visible = true;
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = ex.Message;
            }

https://azure.microsoft.com/en-gb/documentation/articles/storage-dotnet-how-to-use-tables/

Advertisements

One thought on “Windows Azure storage tables – How to delete a table in C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s