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"; ...

Get Introducing .NET 4.0: with Visual Studio 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.