One major change in the configuration of Silverlight beta 2 is the configuration of DRM and application storage.
The default size of application storage is 1 MB. You can modify the code by using the isolatedstoragefile class. The isolatedstoragefile class abstracts the Virtual File System of isolated storage. you can create an isolatedstoragefile instance to list or manage files or folders. you can also use the isolatedstoragefilestream object of this class to manage file content.
The root directory of the virtual file system is different for the current login users of each machine. It is a hidden folder and exists in the physical file system. different identifiers of each application will map them to different folders, that is, they will be allocated to each different application a Virtual File System belonging to it .. the folder structure and hidden architecture in. NET Framework Version 2.0 are also in.. NET Framework for Silverlight is also used.
var store = IsolatedStorageFile.GetUserStoreForApplication()
Store. createdirectory ("myapp1 ");
String subdirectory1 = system. Io. Path. Combine ("myapp1", "subdir1 ");
Store. createdirectory (subdirectory1 );
Isolatedstoragefilestream rootfile = store. createfile ("intheroot.txt ");
Rootfile. Close ();
// Write to text file
String filepath = system. Io. Path. Combine (subdirectory1, "myapp1a.txt ");
Try
{
Using (streamwriter Sw =
New streamwriter (store. openfile (filepath,
Filemode. Open, fileaccess. Write )))
{
Sw. writeline ("to do list :");
Sw. writeline ("1. buy supplies .");
}
}
Catch (isolatedstorageexception ex)
{
SB. appendline (ex. Message );
}
// Read from text file
Try
{
Using (streamreader reader =
New streamreader (store. openfile (filepath,
Filemode. Open, fileaccess. Read )))
{
String contents = reader. readtoend ();
SB. appendline (filepath + "Contents :");
SB. appendline (contents );
}
}
Catch (isolatedstorageexception ex)
{
SB. appendline (ex. Message );
}
To use application storage to store data, use isolatedstoragesettings. applicationsettings
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
Now you can use it to read, modify, and delete application configurations:
//Add new appSettingappSettings.Add("email", "alexg@sela.co.il");//Read appSettingstring mailAddress = (string)appSettings["email"];//Change existing appSettingappSettings["email"] = "alex@somemail.com";//and finally delete it...appSettings.Remove("email");
For more information about storage, see
Use isolatestore in Silverlight to isolate storage (on)
Use isolatestore in Silverlight to isolate storage (bottom)
You can adjust the size of the bucket by using the code. The increasequotato () function is used.
The Code is as follows:
Using (VAR store = isolatedstoragefile. getuserstoreforapplication ())
{
// Request 5 MB more space in bytes.
Int64 spacetoadd = 5242880;
Int64 curavail = store. availablefreespace;
// If available space is less
// What is requested, try to increase.
If (curavail <spacetoadd)
{
// Request more quota space.
If (! Store. increasequotato (store. Quota + spacetoadd ))
{
// The user clicked NO to
// Host's prompt to approve the quota increase.
Tbresults. Text = "User declined to approve quota inrease ";
}
Else
{
// The user clicked yes to
// Host's prompt to approve the quota increase.
Tbresults. Text = "quota inreased ";
}
}
}