1
votes

I have an Azure storage connection string and from which I want to read AccountName and Account Key.
I could get the account Name but not the key.
Can anyone suggest me how to read Key?

ConnectionString : DefaultEndpointsProtocol=https;AccountName=dev;AccountKey=tsdsgyduysaugdsay4aR6EPn2Ie9YOILeEp5RRFXeeaJ9;EndpointSuffix=core.windows.net

var cloudStorageAccount = CloudStorageAccount.Parse(ConnectionString);

var storageCredentials = new StorageCredentials(cloudStorageAccount.Credentials.AccountName, cloudStorageAccount.Credentials.KeyName);
1
Why do you need this? Once you have an instance of CloudStorageAccount, you can perform all storage operations. - Gaurav Mantri
I want to create CloudBlockBlob object with fileUri and storage credentials - Balanjaneyulu K
I think it will not be presented because it would lay in memory for no reason. Normally the key is part of the connection string or is put to the config. Would be good to know what you want to achieve here. - Alexander Schmidt
Just use cloudStorageAccount.CreateCloudBlobClient() and so on. docs.microsoft.com/en-us/azure/storage/blobs/… - Alexander Schmidt
How can I do GetBlockBlobReference with full URL? - Balanjaneyulu K

1 Answers

1
votes

So if you have storage credentials (account name and key) and the blob's URI, there're two ways to create an instance of CloudBlockBlob.

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), storageAccount.Credentials);

OR

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), blobClient);