CloudStorageAccount.TryParse Method
Indicates whether a connection string can be parsed to return a CloudStorageAccount object.
Namespace: Microsoft.WindowsAzure
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
public static boolean TryParse ( String value, /** @attribute OutAttribute() */ /** @ref */ CloudStorageAccount account )
Parameters
- value
Type: System.String
The connection string to parse.
- account
A CloudStorageAccount object to hold the instance returned if the connection string can be parsed.
Return Value
Type: System.Booleantrue if the connection string was successfully parsed; otherwise, false.The following code example attempts to parse a connection string and return a CloudStorageAccount object, then lists account, credential, and endpoint information.
static void TryParseCloudStorageAccountFromConnectionString()
{
CloudStorageAccount storageAccount;
if (CloudStorageAccount.TryParse(ConfigurationManager.AppSettings["StorageAccountConnectionString"], out storageAccount))
{
Console.WriteLine("Connection string: {0}", storageAccount.ToString(true));
Console.WriteLine("Account name: {0}", storageAccount.Credentials.AccountName);
Console.WriteLine("Account key: {0}", ((StorageCredentialsAccountAndKey)storageAccount.Credentials).Credentials.ExportBase64EncodedKey());
Console.WriteLine("Blob endpoint: {0}", storageAccount.BlobEndpoint);
Console.WriteLine("Queue endpoint: {0}", storageAccount.QueueEndpoint);
Console.WriteLine("Table endpoint: {0}", storageAccount.TableEndpoint);
}
else
{
Console.WriteLine("The connection string could not be parsed.");
}
}
The TryParse method attmempts to parse a connection string and returns a reference to a CloudStorageAccount object. For details on working with connection strings, see How to Configure Connection Strings.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Development Platforms
Windows Vista, Windows 7 and Windows Server 2008Target Platforms
This throws UriFormatException for connection string with spaces
Just a warning - CloudStorageAccount.TryParse actually throws when given a connection string with a space between the AccountName= and the account name. It appears AccountKey is properly stripped of leading/trailing spaces though (or they don't matter to the decryption somehow). I've submitted a patch to the GitHub repo to fix this issue.
- 4/22/2012
- Doug Rohrer
- 4/23/2012
- Doug Rohrer