CloudStorageAccount.TryParse Method

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

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

Visual Basic
Dim value As String
Dim account As CloudStorageAccount
Dim returnValue As Boolean

returnValue = CloudStorageAccount.TryParse(value, account)

Syntax

Visual Basic
Public Shared Function TryParse ( _
	value As String, _
	<OutAttribute> ByRef account As CloudStorageAccount _
) As Boolean
C#
public static bool TryParse (
	string value,
	out CloudStorageAccount account
)
C++
public:
static bool TryParse (
	String^ value, 
	[OutAttribute] CloudStorageAccount^% account
)
J#
JScript

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.

Example

The following code example attempts to parse a connection string and return a CloudStorageAccount object, then lists account, credential, and endpoint information.

C# Copy Code
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.");
    }
}

Remarks

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.


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also