Overview
IsolatedstoragefileMember
An independent storage area that contains files and directories.
Isolatedstoragefile. getuserstoreforapplication
Obtain the application called from the VM domainProgramIndependent storage of the user range used.
IsolatedstoragefilestreamMember
Open files in independent storage.
StreamwriterMember
Implement a textwriter so that it writes characters to the stream in a specific encoding.
Note:
The default storage space for the user's independent storage is 1 MB, so there may be no space for large files. In this case, the user's independent storage can be expanded.
Silverlight browser Interaction: computing and expansion of independent storage space of Silverlight users
Effect
XAMLCode:
< Grid X: Name = "Layoutroot" Background = "White" >
< Stackpanel >
< Button X: Name = "Write"
Width = "150"
Height = "50"
Margin = "5"
Content = "Creating files"
Click = "Write_click" />
< Button X: Name = "Read"
Width = "150"
Height = "50"
Margin = "5"
Content = "Reading files"
Click = "Read_click" />
< Textblock X: Name = "Mytextblock" Text = "" Textwrapping = "Wrap" Margin = "5" />
</ Stackpanel >
</ Grid >
CS code:
/// <Summary>
/// Create File and write content
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Write_click ( Object Sender, routedeventargs E)
{
// Isolatedstoragefile Member
// Isolatedstoragefile. getuserstoreforapplication obtains the independent storage of the user range used by the application called from the VM domain.
Using (VAR isofile = Isolatedstoragefile. getuserstoreforapplication ())
{
// Isolatedstoragefilestream Member
// Open files in independent storage.
Using (VAR stream = New Isolatedstoragefilestream ( " File.txt " , Filemode. Create, isofile ))
{
// Streamwriter Member
// Implement a textwriter so that it writes characters to the stream in a specific encoding.
Using (VAR writer = New Streamwriter (Stream ))
{
Writer. Write ( " Creation Time: " + Datetime. Now );
}
Stream. Close ();
MessageBox. Show ( " File Created! " );
}
}
}
/// <Summary>
/// Search for and read the file content
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Read_click ( Object Sender, routedeventargs E)
{
Using (VAR isofile = Isolatedstoragefile. getuserstoreforapplication ())
{
Using (VAR stream = New Isolatedstoragefilestream ( " File.txt " , Filemode. Open, isofile ))
{
Using (VAR writer = New Streamreader (Stream ))
{
Mytextblock. Text = Writer. readtoend () + " Read time: " + Datetime. now;
}
Stream. Close ();
// Isofile. deletefile ("file1.txt ");
}
}
}
Success !!!
Author:Memories of lost youth
Source:Http://www.cnblogs.com/lukun/
The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent andArticleThe original text connection is displayed at an obvious location on the page. If you have any problems, you can useHttp://www.cnblogs.com/lukun/ Thank you very much for contacting me.