Reader Level:
Article

Fetching all Table Names in Windows Azure

By Dhananjay Kumar on Nov 11, 2011
Here you will see how to fetch all table names in Windows Azure.

To list all the table names from a Windows Azure storage account, you need to call the  ListTable() function of the CloudTableClient class. To start with, first you need to add the below namespaces.

FchWinAzr1.gif

Then create a storage account as below,

FchWinAzr2.gif

Make sure to put your own connection string to azure storage to parse. Next you need to create instance of table client

FchWinAzr3.gif

Once a tableclient is created you can list all the tables by making call to ListTables() method.

FchWinAzr4.gif

For your reference, the full source code to fetch all the tables name from a Windows Azure Storage account is given below,

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
namespace ConsoleClient
{
    class Program
    {
        static void Main(string[] args)
        {

            string connectionString = "DefaultEndpointsProtocol=https;AccountName=abc;AccountKey=jsjdsfjgdsfj09===";
            var TablesName = GetTablesNameForAzureSubscription(connectionString);
            foreach (var r in TablesName)
            {
                Console.WriteLine(r.ToString());
            } 

            Console.ReadKey(true);
        }

        private static List<string> GetTablesNameForAzureSubscription(string connectionString)
        {           
            CloudStorageAccount account =CloudStorageAccount
                                         .Parse(connectionString);

            CloudTableClient tableClient = new CloudTableClient
                                       (account.TableEndpoint.ToString(),
                                       account.Credentials);

            var result = tableClient.ListTables();

            return result.ToList();
        }


On running of above code you should be getting the table name listed for the account mentioned in connection string. In this case I have three tables listed to the account as below,

FchWinAzr5.gif

In this way you can list all the tables name from Windows Azure Storage Account. I hope this post is useful. Thanks for reading. 

Dhananjay Kumar

Dhananjay kumar is 6 times Microsoft MVP, 7 times C# Corner MVP. He works as consultant for Infragistics in India. He is known for mentoring teams on various technologies.

Personal Blog: http://debugmode.net/

COMMENT USING