We are able to get container name using the code below:
new CloudBlobContainer(url).Name
But this method works only if the URL is container base URL.
If we are trying to pass the URL of a file and try to get the container name, the code will not return data as expected. In this case, we have to use the CloudBlockBlob object.
new CloudBlockBlob(new Uri(Url)).Container.Name
Is there any method to get a container name that will work for URLs listed below:
http://127.0.0.1:10000/devstoreaccount1/10d59357-b4d1-41e8-ba2a-d92964e1ac53
http://127.0.0.1:10000/devstoreaccount1/10d59357-b4d1-41e8-ba2a-d92964e1ac53/temp/1.txt
Older SDK (9.3.3)
If you're using older SDK (9.3.3), You can use BlobClient
and the name of the blob container will be available in BlobContainerName
property.
BlobClient client = new BlobClient(new Uri(url));
Newer SDK (12.2.0)
For newer SDK (12.2.0), you can use BlobUriBuilder
and the name of the blob container will be available in BlobContainerName
property.
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(new Uri(url));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With