ARTICLE

Fetching all Table Names in Windows Azure

Posted by Dhananjay Kumar Articles | Windows Azure November 11, 2011
Here you will see how to fetch all table names in Windows Azure.
Reader Level:

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. 

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter