首先,在存储配置数据时,您有两种选择:
Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
这将使用漫游配置文件空间,因此它将存储在云或域配置文件中
Windows.Storage.ApplicationDataContainer settings = Windows.Storage.ApplicationData.Current.LocalSettings;
这将使用本地配置文件空间
当然,它们最终都将存储在您的用户 %appdata% 下,但如果我正确理解所有内容,漫游的实际上将被同步 :)
因此,对于您希望存储在另一个分区上的应用程序数据:
首先您需要使用 FolderPicker 选择位置
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
//Add some other yada yada to make the picker work as needed
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
然后你需要把选中的文件夹放到一个访问列表中,记住它是允许使用这个文件夹的
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
这样应用程序/系统将跟踪它是否允许在将来使用此文件夹。所选文件夹可能位于文件系统中您有权访问的任何位置。
最后,如果您不想在下次启动应用程序时取回所选文件夹,则只需执行相反的操作:
StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("TargetFolderToken",AccessCacheOptions.FastLocationsOnly);
值 FastLocationsOnly 意味着它只会返回本地驱动器。 “TargetFolderToken”与您将文件夹存储在 FutureAccessList 中时使用的标识符相同。