RoleEnvironment.GetLocalResource Method (Microsoft.WindowsAzure.ServiceRuntime)

Switch View :
ScriptFree
RoleEnvironment.GetLocalResource Method
Retrieves a specified local storage resource.

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime)
Usage

Visual Basic
Dim localResourceName As String
Dim returnValue As LocalResource

returnValue = RoleEnvironment.GetLocalResource(localResourceName)
Syntax

Visual Basic
<SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode:=True)> _
Public Shared Function GetLocalResource ( _
	localResourceName As String _
) As LocalResource
C#
[SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode=true)] 
public static LocalResource GetLocalResource (
	string localResourceName
)
C++
[SecurityPermissionAttribute(SecurityAction::Assert, UnmanagedCode=true)] 
public:
static LocalResource^ GetLocalResource (
	String^ localResourceName
)
J#
/** @attribute SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode=true) */ 
public static LocalResource GetLocalResource (
	String localResourceName
)
JScript
public static function GetLocalResource (
	localResourceName : String
) : 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.
Exceptions

Exception type Condition
RoleEnvironmentException

The local storage resource does not exist.

Remarks

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

C#

// 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);
}

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 and Windows Server 2008

Target Platforms

Change History

See Also