List all file share from storage account using azure .net SDK or Fluent API?

605 views Asked by At

I want to show all file share from storage account. I have storage account dropdown so whenever user will select particular storage account name i want to fetch all file share name associated with selected storage account. I want any Fluent API or REST API.

1

There are 1 answers

7
Cindy Pau On BEST ANSWER
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);
            }

        }
    }
}

And this is the REST API:

https://learn.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>