Reputation: 2444
I am trying to get a list of all tables on Microsoft Azure storage. I am able to connect successfully and read rows from the table if i know the name of the table. There is a method to get list of tables with the following definition:
public virtual IEnumerable<CloudTable> ListTables(string prefix = null, TableRequestOptions requestOptions = null, OperationContext operationContext = null);
Now my question is if i don't pass any parameters would i expect to get a list of all tables. I tried passing "*" for prefix as well which also didn't seem to yield me any results.
Here is my code:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
IEnumerable<CloudTable> tableList = tableClient.ListTables("*");//returns empty list
IEnumerable<CloudTable> tableList = tableClient.ListTables();//returns empty list
Upvotes: 2
Views: 5195
Reputation: 129
Code:
public static void list_queue()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("xxxxxxxxxxxxxxxxxxxxxx_AzureStorageConnectionString"));
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
var result = queueClient.ListQueues();
if (result != null)
{
foreach (var item in result)
{
Console.WriteLine(item.Name);
}
}
}
Output:
Upvotes: -1
Reputation: 129
Code to display all the tables in Azure storage account:
public static void list_table()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("xxxxxxxxxxxxxxxxxxxxxx_AzureStorageConnectionString"));
CloudTableClient tableClient = new CloudTableClient(storageAccount.TableEndpoint, storageAccount.Credentials);
var result = tableClient.ListTables();
if(result != null)
{
foreach (var item in result)
{
Console.WriteLine(item.Name);
}
}
}
The output will be:
Upvotes: 6
Reputation: 2444
So turns out my code does indeed work. The client informed me that there were tables but apparently they were mistaken.
NOTE: Using "*" as a prefix does not yield results but not passing any parameters will give list of tables.
Upvotes: 0
Reputation: 1675
Does this code work for you? You may want to hard-code the connect string temporarily.
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=MyAccountName;AccountKey=MyAccountKey===";
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();
}
Upvotes: 3