本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

RoleEnvironment.GetLocalResource 方法 (String)

 

擷取指定的本機儲存體資源。

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

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

參數

localResourceName
Type: System.String

類型: System.String

ServiceDefiniton.csdef 檔案中定義的本機儲存資源名稱。

Exception Condition
RoleEnvironmentException

本機儲存體資源不存在。

下列程式碼範例示範如何使用這個方法來擷取本機儲存體資源並將文字檔寫入至資源:

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

回到頁首
顯示: