CloudStorageAccount.TryParse Method
From Storage Client Library NET API
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# | |
|---|---|
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.