16.5. Local Storage

Local storage is an area to which you can temporarily save files, and it can be useful for caching, uploading, and serialization. Warning—you should not save anything here you want to keep since local storage will be cleared if your application restarts.

To use local storage, simply add a new entry to ServiceDefinition.csdef to define the storage area:

<LocalStorage name="MyStorage"/>

Once you have defined the storage, you can now use the RoleEnvironment.GetLocalResource() method to return a LocalResource object that allows you to utilize the file. The following example shows how to save a file to local storage:

LocalResource resource = RoleEnvironment.GetLocalResource("MyStorage");
string Path = resource.RootPath + "messages.txt";
string FileContents = "Hello Azure";
System.IO.File.WriteAllText(Path, FileContents);

If you want to see items that have been saved in the development fabric's local storage with the previous code, then you can right-click the web role, select the "Open local storage" option, and browse to Directory/MyStorage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.206.105