Exportera (0) Skriv ut
Visa allt
EN
Det här innehållet finns inte tillgängligt på ditt språk men här finns den engelska versionen,
2 av 4 bedömde detta vara till hjälp - Bedöm det här ämnet

RoleEnvironment.GetLocalResource Method

Retrieves a specified local storage resource.

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)
'Användning

'Deklaration
<SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode:=True)> _
Public Shared Function GetLocalResource ( _
	localResourceName As String _
) As LocalResource

Parameters

localResourceName

Type: System.String

The name of the local storage resource that is defined in the ServiceDefiniton.csdef file.

Return Value

Type: Microsoft.WindowsAzure.ServiceRuntime.LocalResource

An instance of LocalResource that represents the local storage resource.
Exception typeCondition
RoleEnvironmentException

The local storage resource does not exist.

The following code example shows how to use this method to retrieve the local storage resource and write a text file to the resource:

try
{
    // Retrieve an object that points to the local storage resource.
    LocalResource localResource = RoleEnvironment.GetLocalResource("localStoreTwo");

    // Define the file name and path.
    string[] paths = { localResource.RootPath, "MyStorageTest.txt" };
    String filePath = Path.Combine(paths);

    using (FileStream writeStream = File.Create(filePath))
    {
        Byte[] textToWrite = new UTF8Encoding(true).GetBytes("Testing Web role storage");
        writeStream.Write(textToWrite, 0, textToWrite.Length);
    }
}
catch (RoleEnvironmentException e)
{
    Console.WriteLine("The local resource isn't defined or doesn't exist. \n" + e.ToString());
}


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

Var detta till hjälp?
(1500 tecken kvar)
Tack för dina kommentarer

Gruppinnehåll

Lägg till
Visa:
© 2014 Microsoft. Med ensamrätt.