wp8.1 Study10:APP資料存放區

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   使用   sp   on   

一、理論

1、App的各種資料在WP哪裡的?

很好介紹了這個問題。有InstalltionFolder, knownFolder, SD Card...

2、一個App的資料儲存概覽

主要分兩大部分,InstallationFolder和App Data Folder

 

3、Windows.Storage.ApplicationData  和  Windows.Security.Credentials簡述

 

其中利用Windows.Storage.ApplicationData,我們可以獲得3種不同的wp中檔案夾和2種設定儲存字典,C#操作如下

 Windows.Storage.StorageFolder roam = Windows.Storage.ApplicationData.Current.RoamingFolder; Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFolder temp = Windows.Storage.ApplicationData.Current.TemporaryFolder; Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

 

二、Local Folder 和 Local Setting

1、LocalSetting使用,C#代碼如下:

// Create a simple settinglocalSettings.Values["exampleSetting"] = "Hello Windows";// Read data from a simple settingObject value = localSettings.Values["exampleSetting"];if (value == null){    // No data}else{    // Access data in value}// Delete a simple settinglocalSettings.Values.Remove("exampleSetting");

2、LocalFolder使用,C#代碼如下:

  private async void writeTextToLocalStorageFile(string filename, string text)        {            var fold = Windows.Storage.ApplicationData.Current.LocalFolder;//開啟檔案夾            StorageFile file = await fold.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);//建立個檔案            await FileIO.WriteTextAsync(file, text);//在檔案裡面寫內容        }        private async Task<string> readTextFromLocalStorage(string filename)        {            var fold = Windows.Storage.ApplicationData.Current.LocalFolder;//開啟檔案夾            StorageFile file = await fold.GetFileAsync(filename);//開啟對應的檔案            string result = await FileIO.ReadTextAsync(file);//讀取檔案裡面的內容            return result;        }

Note:這裡對檔案的操作是十分簡單的,步驟是在電腦管理檔案的步驟是類似的。

 

三、Roaming Setting 和Roaming Folder

如果使用者在多個裝置上安裝了你的程式,如果所有的裝置可以共用相同的設定資訊是很好的體驗。而Roaming data提供了一個應用程式可以在多個不同的物理裝置同步資料和設定方法。它以一個檔案夾和設定字典的形式自動儲存在使用者的OneDrive。Roaming data的大小限制於ApplicationData.RoamingStorageQuota(一般是100k左右,但它不會佔用你Onedrive的空間大小)。其同步過程圖如下:

  Roaming Setting 和Roaming Folder的操作方式與上面的Local Folder 和 Local Setting操作方式一樣,在這不一一介紹。但是需要在不同裝置中監視Roaming data的改變事件。C#代碼如下:

Windows.Storage.ApplicationData.Current.DataChanged += Current_DataChanged;...void Current_DataChanged(ApplicationData sender, object args){    // Refresh your settings...}

  資料的同步是發生在背景。

四、幾種不同方式擷取檔案的方式

 

wp8.1 Study10:APP資料存放區

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.