c# - 列出 Azure 存储帐户 .NET core 中的所有现有表

标签 c# azure asp.net-core azure-storage azure-table-storage

如何获取在我的 Azure 存储帐户中创建的所有现有表?

你以前是这样的

CloudTableClient tableClient;
IEnumerable<CloudTable> AllTables = tableClient.ListTables();

但是,我似乎无法在 CloudTableClient 实例上调用 ListTables 方法。我正在使用 Microsoft.WindowsAzure.Storage 版本 9.3.0

EDIT

这是针对.NET CORE的

最佳答案

Go straight to the EDIT paragraph below if you looking for the .NET core answer

嗯,看来您没有创建 tableClient 的实例

    CloudTableClient tableClient = new CloudTableClient("YOUR CONNECTION STRING");
    var AllTables = tableClient.ListTables();          
    if(AllTables != null)
    {
        foreach (var table in AllTables)
        {
            // table.Name is your property
        } 
    }

该方法在微软文档上

https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.cloudtableclient.listtables?view=azure-dotnet#Microsoft_WindowsAzure_Storage_Table_CloudTableClient_ListTables_System_String_Microsoft_WindowsAzure_Storage_Table_TableRequestOptions_Microsoft_WindowsAzure_Storage_OperationContext_

EDIT

除此之外,OP 刚刚表示他们正在使用 .NET CORE

.NET Core 尚未包含 API 的同步实现

ListTables 没有方法,因此您必须使用 ListTablesSegmentedAsync 并传入 null 作为 continuationToken 参数。这将继续循环,直到获取所有表为止

https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.cloudtableclient.listtablessegmentedasync?view=azure-dotnet#Microsoft_WindowsAzure_Storage_Table_CloudTableClient_ListTablesSegmentedAsync_Microsoft_WindowsAzure_Storage_Table_TableContinuationToken_

更新示例代码

这是列出所有表的伪代码

CloudTableClient tableClient = new CloudTableClient("YOUR CONNECTION STRING");
TableContinuationToken continuationToken = null;
var allTables = new List<CloudTable>();
do
{
  var listingResult = await tableClient.ListTablesSegmentedAsync(continuationToken);
  var tables = listingResult.Result.ToList();
  continuationToken = listingResult.ContinuationToken;
  //Add the tables to your allTables
}
while (continuationToken != null);

...

关于c# - 列出 Azure 存储帐户 .NET core 中的所有现有表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51326275/

相关文章:

c# - 在c#中将点移动到另一个

c# - 比较两个不同 LINQ 语句的效率

Azure Pipeline Secret 环境变量标记为未定义

azure - 使用 php 将 .pbix (power BI) 文件导入工作区(多部分表单数据发布)

azure - 如何仅将特定列从 SQL 表复制到 Azure 数据湖存储

c# - 使用 asp.net core 2.2 恢复 nuget 包时出现问题

c# - 如何对 TextBox.Triggers(事件触发器)执行某些操作?

c# - 如何返回正确的 Http 响应而不是 JSON 对象

LaunchSettings.json中的Asp.Net Core更改URL不起作用

c# - .NET Core 2.1 HttpClient 不返回预期值