Fetching 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. 

Up Next
    Ebook Download
    View all
    Learn
    View all