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.
<Phone: phoneapplicationpage <br/> X: class = "isostoragesample1.mainpage" <br/> xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" <br/> xmlns: X = "http://schemas.microsoft.com/winfx/2006/xaml" <br/> xmlns: Phone = "CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.mi Crosoft.com/expression/blend/2008 "<br/> xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "<br/> MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" portrait "orientation =" por Trait "<br/> shell: systemtray. isvisible =" true "> </P> <p> <! -- Layoutroot is the root mesh that contains all page content --> <br/> <grid X: Name = "layoutroot" background = "Transparent"> <br/> <grid. rowdefinitions> <br/> <rowdefinition Height = "Auto"/> <br/> <rowdefinition Height = "*"/> <br/> </grid. rowdefinitions> </P> <p> <! -- Titlepanel contains the application name and page title --> <br/> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <br/> <textblock X: name = "applicationtitle" text = "my application" style = "{staticresource phonetextnormalstyle}"/> <br/> <textblock X: name = "pagetitle" text = "isolated storage" margin = "9,-7,0, 0 "style =" {staticresource phonetexttitle1style} "/> <br/> </stackpanel> </P> <p> <! -- Contentpanel-place other content here --> <br/> <grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <br/> <textbox Height = "72" horizontalalignment = "Left" margin = "12, 25, 289 "name =" txtdirname "verticalignment =" TOP "width =" "/> <br/> <button content =" CREATE "Height =" 72 "horizontalalignment =" left" margin = "307,25, 127 "name =" btncreate "verticalignment =" TOP "width =" "Click =" btncreate_click "/> <br/> <button content =" check whether the directory already exists "height "= "72" horizontalalignment = "Left" margin = "146,120, 276 "name =" btncheck "verticalignment =" TOP "width =" "Click =" btncheck_click "/> <br/> <button content =" delete directory "Height =" 72 "horizontalalignment =" Left "margin =" 0,283, 422 "name =" btndel "verticalignment =" TOP "width =" "Click =" btndel_click "/> <br/> <textblock Height =" 38 "horizontalalignment =" left" margin = "9,138, 131 "name =" tbdisplay "verticalignment =" TOP "width =" "/> <br/> </GRID> </P> <p> </phone: phoneapplicationpage>
Private void btncreate_click (Object sender, routedeventargs e) <br/>{< br/> // you can return an isolatedstoragefile instance through the getuserstoreforapplication static method. <Br/> isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication (); <br/> try <br/>{< br/> If (ISO. directoryexists (txtdirname. text) <br/>{< br/> return; <br/>}< br/> iso.createdirectory(this.txt dirname. text); <br/>}< br/> catch <br/> {MessageBox. show ("error! ") ;}< Br/>}</P> <p> private void btncheck_click (Object sender, routedeventargs e) <br/>{< br/> isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication (); <br/> bool exists = ISO. directoryexists (txtdirname. text); <br/> If (exists) <br/>{< br/> This. tbdisplay. TEXT = "already exists"; <br/>}< br/> else <br/>{< br/> This. tbdisplay. TEXT = "nonexistent"; <br/>}</P> <p> private void btndel_click (Object sender, routedeventargs e) <br/>{< br/> isolatedstoragefile ISO = isolatedstoragefile. getuserstoreforapplication (); <br/> try <br/>{< br/> ISO. deletedirectory (txtdirname. text); <br/>}< br/> catch <br/>{< br/> MessageBox. show ("error! "); <Br/>}< br/>
Note that the system. Io. isolatedstorage namespace should be introduced.