UpgradetoMicrosoftEdgetotakeadvantageofthelatestfeatures,securityupdates,andtechnicalsupport.
Note
Accesstothispagerequiresauthorization.Youcantrychangingdirectories.
Appdataismutabledatathatisspecifictoaparticularapp.Itincludesruntimestate,userpreferences,andothersettings.Appdataiscreated,read,updated,anddeletedwhentheappisrunning.
WerecommendthatWindowsRuntimeappsuseappdatastoresforsettingsandfilesthatarespecifictoeachappanduser.Thesystemmanagesthedatastoresforanapp,ensuringthattheyarekeptisolatedfromotherappsandotherusers.Thesystemalsopreservesthecontentsofthesedatastoreswhentheuserinstallsanupdatetoyourappandremovesthecontentsofthesedatastorescompletelyandcleanlywhenyourappisuninstalled.
Importantnoteaboutappdata:Thelifetimeoftheappdataistiedtothelifetimeoftheapp.Iftheappisremoved,alloftheappdatawillbelostasaconsequence.Don'tuseappdatatostoreuserdataoranythingthatusersmightperceiveasvaluableandirreplaceable.Werecommendthattheuser'slibrariesandOneDrivebeusedtostorethissortofinformation.Appdataisidealforstoringapp-specificuserpreferences,settings,andfavorites.
Whenanappisinstalled,thesystemgivesititsownper-userdatastoresforappdatasuchassettingsandfiles.Youdon'tneedtoknowwhereorhowthisdataexists,becausethesystemisresponsibleformanagingthephysicalstorage.JustusetheappdataAPI,whichmakesiteasyforyoutoworkwithyourappdata.
Thesearethedatastores:
Ifyourappisremoved,thesedatastoresaredeleted.
Settingsintheappdatastorearestoredintheregistry.WhenyouusetheappdataAPI,registryaccessistransparent.Withinitsappdatastore,eachapphasarootcontainerforsettings.Yourappcanaddsettingsandnewcontainerstotherootcontainer.Createnewcontainerstohelpyouorganizeyoursettings.Notethatcontainerscanbenestedupto32levelsdeep,withnorestrictiononthebreadthofthetree.
Usecompositesettingstoeasilyhandleatomicupdatesofinterdependentsettings.Thesystemensurestheintegrityofcompositesettingsduringconcurrentaccessandroaming.Compositesettingsareoptimizedforsmallamountsofdata,andperformancecanbepoorifyouusethemforlargedatasets.
Appsettingscanbelocalorroaming.Thesettingsthatyourappaddstothelocaldatastorearepresentonlyonthelocaldevice.Thesystemautomaticallysynchronizessettingsyourappaddstotheroamingdatastoreonalldevicesonwhichtheuserhasinstalledtheapp.
Notethatthereisnobinarytype.Ifyouneedtostorebinarydata,useanappfile.
Youcan'tdirectlyassignothertypesofobjectstoappdata.Youcanserializedatatooneofthesupporteddatatypes,forexampleyoucanserializeyourdataasJSONandstoreitasastring,butyouneedtohandletheserialization.
Thesystemensuresthatthesizeofthedatawrittenmatchesthesizeofthedatatype.Thesystemdoesnotvalidatethedata,soyoumustcheckwhetherthedatahaschangedbetweenthetimeyouwriteitandreaditback.
Filesintheappdatastorearestoredinthefilesystem.AppscanusefilesintheappdatastorejustastheyusefilesintheAppDatapartoftheuser'sprofileinWindows7.Withinitsappdatastore,eachapphassystem-definedrootdirectories:oneforlocalfiles,oneforroamingfiles,andonefortemporaryfiles.Yourappcanaddnewfilesandnewdirectoriestotherootdirectory.Createnewdirectoriestohelpyouorganizeyourfiles.Notethatdirectoriesintheappdatastorecanbenestedupto32levelsdeep,withnorestrictiononthebreadthofthetree.
Appfilescanbelocalorroaming.Thefilesthatyourappaddstothelocaldatastorearepresentonlyonthelocaldevice.Thesystemautomaticallysynchronizesfilesyourappaddstotheroamingdatastoreonalldevicesonwhichtheuserhasinstalledtheapp.
Forexamplecode,see:
Ifyouuseroamingdatainyourapp,youruserscaneasilykeepyourapp'sappdatainsyncacrossmultipledevices.Ifauserinstallsyourapponmultipledevices,theOSkeepstheappdatainsync,reducingtheamountofsetupworkthattheuserneedstodoforyourappontheirseconddevice.Roamingalsoenablesyouruserstocontinueatask,suchascomposingalist,rightwheretheyleftoffevenonadifferentdevice.TheOSreplicatesroamingdatatothecloudwhenitisupdated,andsynchronizesthedatatotheotherdevicesonwhichtheappisinstalled.
Iftheappdataonadeviceisupdatedtoanewversionbecausetheuserinstalledanewerversionoftheapp,itsappdataiscopiedtothecloud.Thesystemdoesnotupdateappdatatootherdevicesonwhichtheuserhastheappinstalleduntiltheappisupdatedonthosedevicesaswell.
Theoperatingsystemroamsappdataopportunisticallyanddoesn'tguaranteeaninstantsync.Inscenarioswhereauserisofflineoronahighlatencynetwork,roamingcouldbedelayedsignificantly.Forimportant,timecriticalsettingsaspecialhighprioritysettingsunitisavailablethatprovidesmorefrequentupdates.Itislimitedtoonespecificsettingsunitthatmustbenamed“HighPriority”.Itcanbeacomposite,butthetotalsizeislimitedto8KB.Thislimitisnotenforcedandthesettingunitorsettingcompositewillbetreatedasaregularsettingunitoracompositeincasethelimitisexceeded.