【问题标题】:List all file share from storage account using azure .net SDK or Fluent API?使用 azure .net SDK 或 Fluent API 列出存储帐户中的所有文件共享?
【发布时间】:2021-08-19 20:56:31
【问题描述】:

我想显示存储帐户中的所有文件共享。我有存储帐户下拉列表,因此每当用户选择特定的存储帐户名称时,我都想获取与所选存储帐户关联的所有文件共享名称。我想要任何 Fluent API 或 REST API。

【问题讨论】:

  • .NET SDK 或 REST API 能否满足您的要求?
  • @Bowman Zhu 目前在我的项目中,我使用的是 azure fluent api,但使用它我无法获取 azure 文件共享的详细信息,所以我正在寻找其他方法。所以请帮助我。

标签: c# azure-sdk-.net azure-sdk azure-fluent-api


【解决方案1】:
using System;
using System.Threading.Tasks;
using Azure.Storage.Files.Shares;
using Azure.Storage.Files.Shares.Models;

namespace ConsoleApp5
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("xxxxxxxxxxxxxxxxxxxxx");
            string connectionString = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net";

            ShareServiceClient ssc = new ShareServiceClient(connectionString);
            foreach (ShareItem item in ssc.GetShares())
            {
                Console.WriteLine(item.Name);
            }

        }
    }
}

这是 REST API:

https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares

.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.6.2" />
  </ItemGroup>

</Project>

【讨论】:

  • 感谢您的回复,但是对于 ShareServiceClient 类,我目前应该安装哪个 nuget 包,我已经安装了 Install-Package Azure.Storage.Files.Shares -Version 12.6.2 但无法正常工作
  • @DnyaneshSurya 你得到了什么?
  • 找不到类型或命名空间声音。您是否缺少程序集参考。但我正确安装并添加了参考 Azure.Storage.Files.Shares 但仍然得到。
  • @DnyaneshSurya 我已经更新了 .csproj 文件。
  • 非常感谢............构建项目后它现在可以工作了。
猜你喜欢
  • 1970-01-01
  • 2017-04-11
  • 2015-03-17
  • 2018-11-12
  • 1970-01-01
  • 2014-05-02
  • 2020-01-20
  • 2021-10-17
  • 1970-01-01
相关资源
最近更新 更多