本文由机器翻译。若要查看英语原文,请勾选“英语”复选框。 也可将鼠标指针移到文本上,在弹出窗口中显示英语原文。
翻译
英语

RoleEnvironment.GetLocalResource 方法 (String)

 

检索指定的本地存储资源。

命名空间:   Microsoft.WindowsAzure.ServiceRuntime
程序集:  Microsoft.WindowsAzure.ServiceRuntime(Microsoft.WindowsAzure.ServiceRuntime.dll 中)

[SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode = true)]
public static LocalResource GetLocalResource(
	string localResourceName
)

参数

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

返回页首
显示: