Home > front end >  Is there a better way to List Queues in an Azure Storage Account in C#?
Is there a better way to List Queues in an Azure Storage Account in C#?

Time:08-12

I'm stuck trying to get all the queues in an Azure Storage Account in C#. I've been trying to use the API endpoint shown here:

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

But it seems to be extremely old. It doesn't support bearer tokens and instead requires a SharedKey, the code I found to generate a SharedKey is also very old and can be found here (in the sample application):

https://docs.microsoft.com/en-us/azure/storage/common/storage-rest-api-auth

Before I commit to this course of action, I wanted to ask if anyone knows any better/more up to date way to get a list of all the queues in a given Azure Storage Account?

CodePudding user response:

You can use the Azure Storage Queues client library for .NET to perform management operations like these.

The QueueServiceClient class has a method GetQueues that will list all queues in an account, see the docs

CodePudding user response:

You can use the below code to List Queues in an Azure Storage Account using C#.

QueueServiceClient serviceClient = new QueueServiceClient(conn_str);
        
        //list all queues in the storage account
        var myqueues = serviceClient.GetQueues().AsPages();

        //then you can write code to list all the queue names          
        foreach (Azure.Page<QueueItem> queuePage in myqueues)
        {
            foreach (QueueItem q in queuePage.Values)
            {
                Console.WriteLine(q.Name);
            }

        }

        //get a queue client
        var myqueue_client = serviceClient.GetQueueClient("the queue name");

For more information you can refer this link.

  • Related