[UWP] up-posture UWP source--isolatedstorage

Source: Internet
Author: User

up Posture UWP Source analysis from the data source to explain the RSS feed to get and parse, this article will be on the data source saving and reading for example.

Like the previous Windows Runtime , theUWP uses isolatedstorage to store the app 's private data, so the app Between the non-interference, reducing the error and security risks. Now the design of application seems to be popular in this practice.

Uwp Access to the application data store typically using applicationdata This class to operate, we list some of the most common properties:

Properties and methods

Purpose

public Storagefolder localfolder {get;}

Gets the root folder in the local application data store.

public Applicationdatacontainer localsettings {get;}

Gets the application settings container in the local application data store.

public Storagefolder roamingfolder {get;}

Gets the root folder in the roaming Application data store.

public Applicationdatacontainer roamingsettings {get;}

Gets the application settings container in the roaming Application data store.

public iasyncaction Clearasync ();

specifically in the posture uwp Applicationdata.current.localfolder get current app corresponding to the root folder of the storage space , and then ZH-CN createfilestoragefolder operations , note that creationcollisionoption.replaceexistingrss feed files overwrite existing files.

Next, you need to convert the contents of the string you want to save into an encoded buffer object, and then write it to the previously created file by using the Fileio.writebufferasync method. Of course, you directly Fileio.writetextasync also not can not,Cryptographicbuffer mainly contains encode,Decode Encoding-related methods that can be used for cryptographic operations.

         Public Asynctask<BOOL> Saverssfileasync (stringcontent) {            BOOLIswritesuccess =true; Try{storagefolder Storagefolder=ApplicationData.Current.LocalFolder; StorageFile Rssfile=awaitStoragefolder.createfileasync (Rssfilename, creationcollisionoption.replaceexisting); varBuffer =cryptographicbuffer.convertstringtobinary (content, Binarystringencoding.utf8); awaitFileio.writebufferasync (rssfile, buffer); }            Catch(Exception) {iswritesuccess=false; }            returniswritesuccess; }

Uwp File Store related classes, in addition to the above mentioned windows.storage most commonly used storagefolderstoragefile fileiowindows.storage.pickers< Span lang= "ZH-CN" > various picker, various buffersteam, familiar with later use is very convenient.

Then we look at the operation to read the contents of the file, the same is found localfolder, and then according to the filename to read the StorageFile, if the StorageFile is not empty, through Readtextasync method to get the stored text content.

         Public Asynctask<string>Readrssfileasync () {stringContent =string.            Empty; Storagefolder Storagefolder=ApplicationData.Current.LocalFolder; StorageFile Rssfile=awaitStoragefolder.trygetitemasync (Rssfilename) asStorageFile; if(Rssfile! =NULL) {content=awaitFileio.readtextasync (Rssfile); }            returncontent; }

File preservation and reading is roughly the above, is not more simple than the imagination. Last week's rise in the UWP updated a version, fixed some unspeakable bugs, optimized (or smeared) part of the interface, welcome to the posture.

GitHub Source code address:

Https://github.com/manupstairs/ZhangZiShiRSSRead

Windows Store:

Https://www.microsoft.com/zh-cn/store/p/%e6%b6%a8%e5%a7%bf%e5%8a%bfuwp/9nblggh3zqd1

[UWP] up-posture UWP source--isolatedstorage

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.