This topic has not yet been rated - Rate this topic

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)
'Usage
Dim value As String
Dim account As CloudStorageAccount
Dim returnValue As Boolean

returnValue = CloudStorageAccount.TryParse(value, account)
public static bool TryParse (
	string value,
	out CloudStorageAccount account
)
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.Boolean

true 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 2008

Target Platforms

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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.