WP7 independent storage isolatedstoragefile usage and demo

Source: Internet
Author: User

The code is simple and suitable for beginners

First, add several widgets on the foreground page.

1 <! -- Contentpanel-place other content here --> 2 <grid X: Name = "contentpanel" grid. row = "1" margin = "380,"> 3 <textbox name = "isotextbox" 4 Height = "70" 5 width = "" 6 margin =, 33,467 "7/> 8 <textblock name =" quotatextblock "margin =" 12,164, 0, 0 "9 horizontalalignment =" Left "10 verticalalignment =" TOP "Height =" 50 "width =" 438 "/> 11 <button name =" iso_button "12 Height =" 70" 13 width = "180" 14 content = "write" 15 click = "iso_button_click" 16/> 17 <button name = "iso_button1" 18 Height = "70" 19 width = "180 "20 content =" read "21 click =" iso_button_click1 "margin =" 138,327,138,210 "/> 22 <textblock Height =" 50 "horizontalalignment =" Left "margin =" 9,231, 438 "name =" freetextblock "verticalignment =" TOP "width =" "/> 23 </GRID>

 

 

Background code Initialization

1 Loaded += new RoutedEventHandler(MainPage_Loaded);
1 void MainPage_Loaded(object sender, RoutedEventArgs e)2         {3             IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication();4 5             quotaTextBlock.Text = String.Format("quota:{0}", appStorage.Quota.ToString());6 7             freeTextBlock.Text = String.Format("free:{0}", appStorage.AvailableFreeSpace.ToString());8         }

 

Write button Event code

 
 1         private void Iso_Button_Click(object sender, RoutedEventArgs e) 2         { 3             IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication(); 4             string fileName = "test.txt"; 5  6  7             using (IsolatedStorageFileStream appStream = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate)) 8             { 9                 using (StreamWriter writer = new StreamWriter(appStream))10                 {11                     writer.Write(isoTextBox.Text);12                 }13             }14         }

 

Read button Event code

 1         private void Iso_Button_Click1(object sender, RoutedEventArgs e) 2         { 3             using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication()) 4             { 5                 using (StreamReader reader = new StreamReader(appStorage.OpenFile("test.txt", FileMode.Open))) 6                 { 7                     isoTextBox.Text = reader.ReadLine(); 8                 } 9             }10 11         }

 

This is the end.

Isolatedstoragefile is used for independent storage to store the content in the test.txt file.

Then, you can use streamreader to read and retrieve data.

Upload 1 minute ago

Download Attachment(23.32 KB)

Source code download http://vdisk.weibo.com/s/6VCiW

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.