Interaction with the Silverlight Browser: Creation and reading of files in the independent bucket of the Silverlight user

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.