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