匯出 (0) 列印
全部展開

RoleEnvironment.GetLocalResource 方法

Retrieves a specified local storage resource.

命名空間: Microsoft.WindowsAzure.ServiceRuntime
組件: Microsoft.WindowsAzure.ServiceRuntime (在 microsoft.windowsazure.serviceruntime.dll 中)

'用途
Dim localResourceName As String
Dim returnValue As LocalResource

returnValue = RoleEnvironment.GetLocalResource(localResourceName)

public static LocalResource GetLocalResource (
	string localResourceName
)
public static LocalResource GetLocalResource (
	String localResourceName
)
public static function GetLocalResource (
	localResourceName : String
) : LocalResource

參數

localResourceName

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

傳回值

An instance of LocalResource that represents the local storage resource.

例外狀況類型條件
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:


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

任何這個類型的公用靜態 (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。 並非所有的執行個體成員都是安全執行緒。

開發平台

Windows XP Home Edition, Windows XP Professional, Windows Server 2003、Windows Server 2008 和 Windows 2000

目標平台

社群新增項目

顯示:
© 2014 Microsoft