Windows Phone development (27): isolated storage turn: http://blog.csdn.net/tcjiaan/article/details/7425212

Source: Internet
Author: User

I have translated many documents or books into "independent storage". However, I thought about it and decided to translate isolatedstorage into "isolated storage ", I think this will make it easier for you to understand this concept.
According to the inherent habits of isolated storage, I don't want to make too many theoretical explanations. Theoretically, things are easy to complicate simple things, even if you say how perfect your theoretical knowledge is, I believe everyone is not interested in it. Even if you are interested, you will be confused.

Isolated storage is not unique to WP. It also exists in Silverlight or WPF. More accurately, "independent storage" is available in. NET 2.0 has already appeared. Maybe you didn't notice it, don't believe it? You can find it in the. NET class library.

It doesn't matter if you haven't paid attention to it before. Isolated storage is actually very simple. To put it bluntly, it is the Directory and file management on Windows Phone. on Windows platform, these operations are believed to have been done. net Development friends are certainly very familiar.

The directory and file management methods of Windows Phone are different from those of Windows CE or Windows Mobile in the past. In the past, relative paths were used on both operating systems, and their operation methods were similar to those on PC systems; WP is different. Although relative paths are also used, the operation methods and principles are different.

This is why I want to translate it into "isolated storage". In this way, you can literally guess its features. Each application can only access its independent storage space, you cannot access the directories and structures of other applications or the directories and files of the basic operating system, which greatly improves security.

Okay. Now we only need a simple example and you will understand it.
The example allows you to enter a directory name and click "CREATE". A directory will be created in the isolated storage, and then click the second button to check whether the directory exists, the third button is used to delete a directory.

 

[HTML]View plaincopyprint?

  1. <Phone: phoneapplicationpage
  2. X: class = "isostoragesample1.mainpage"
  3. Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
  5. Xmlns: Phone = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone"
  6. Xmlns: shell = "CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone"
  7. Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
  8. Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
  9. MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
  10. Fontfamily = "{staticresource phonefontfamilynormal }"
  11. Fontsize = "{staticresource phonefontsizenormal }"
  12. Foreground = "{staticresource phoneforegroundbrush }"
  13. Supportedorientations = "portrait" orientation = "portrait"
  14. Shell: systemtray. isvisible = "true">
  15. <! -- Layoutroot is the root mesh that contains all page content -->
  16. <Grid X: Name = "layoutroot" background = "Transparent">
  17. <Grid. rowdefinitions>
  18. <Rowdefinition Height = "Auto"/>
  19. <Rowdefinition Height = "*"/>
  20. </Grid. rowdefinitions>
  21. <! -- Titlepanel contains the application name and page title -->
  22. <Stackpanel X: Name = "titlepanel" grid. Row = "0" margin = ",">
  23. <Textblock X: Name = "applicationtitle" text = "My applications" style = "{staticresource phonetextnormalstyle}"/>
  24. <Textblock X: Name = "pagetitle" text = "isolated storage" margin = "9,-7,0, 0" style = "{staticresource phonetexttitle1style}"/>
  25. </Stackpanel>
  26. <! -- Contentpanel-place other content here -->
  27. <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
  28. <Textbox Height = "72" horizontalalignment = "Left" margin = "289," name = "txtdirname" verticalalignment = "TOP" width = ""/>
  29. <Button content = "CREATE" Height = "72" horizontalalignment = "Left" margin = "307,25, 127 "name =" btncreate "verticalignment =" TOP "width =" "Click =" btncreate_click "/>
  30. <Button content = "check if the directory already exists" Height = "72" horizontalalignment = "Left" margin = "146,120, 276 "name =" btncheck "verticalignment =" TOP "width =" "Click =" btncheck_click "/>
  31. <Button content = "delete directory" Height = "72" horizontalalignment = "Left" margin = "0,283, 422 "name =" btndel "verticalignment =" TOP "width =" "Click =" btndel_click "/>
  32. <Textblock Height = "38" horizontalalignment = "Left" margin = "9,138, 131" name = "tbdisplay" verticalalignment = "TOP" width = ""/>
  33. </GRID>
  34. </GRID>
  35. </Phone: phoneapplicationpage>

 

[CSHARP]View plaincopyprint?

  1. Private void btncreate_click (Object sender, routedeventargs E)
  2. {
  3. // You can use the getuserstoreforapplication static method to return an isolatedstoragefile instance.
  4. Isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication ();
  5. Try
  6. {
  7. If (ISO. directoryexists (txtdirname. Text ))
  8. {
  9. Return;
  10. }
  11. Iso.createdirectory(this.txt dirname. Text );
  12. }
  13. Catch
  14. {MessageBox. Show ("error! ");}
  15. }
  16. Private void btncheck_click (Object sender, routedeventargs E)
  17. {
  18. Isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication ();
  19. Bool exists = ISO. directoryexists (txtdirname. Text );
  20. If (exists)
  21. {
  22. This. tbdisplay. Text = "already exists ";
  23. }
  24. Else
  25. {
  26. This. tbdisplay. Text = "nonexistent ";
  27. }
  28. }
  29. Private void btndel_click (Object sender, routedeventargs E)
  30. {
  31. Isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication ();
  32. Try
  33. {
  34. ISO. deletedirectory (txtdirname. Text );
  35. }
  36. Catch
  37. {
  38. MessageBox. Show ("error! ");
  39. }
  40. }

 

Note that the system. Io. isolatedstorage namespace should be introduced.

 

 

 

Related Article

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.