我正在尝试存储一个文件夹列表,以便以后可以访问它们。 (我之前已将它们添加到FutureAccessList
)
List<StorageFolder> folders = new List<StorageFolder>();
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// ...
Windows.Storage.ApplicationDataCompositeValue data = new Windows.Storage.ApplicationDataCompositeValue();
foreach (var item in folders)
{
if (item.Path == null || item.Path == "")
continue;
data[item.FolderRelativeId] = item.Path; // this is the line where I get the exception
}
localSettings.Values["folders"] = data;
我不明白为什么我一直收到这个错误:
An exception of type 'System.Exception' occurred in mscorlib.dll but was not handled in user code
WinRT information: Error trying to write setting in application data composite value
有人可以帮助我吗?
答案 0 :(得分:2)
不需要ApplicationDataCompositeValue。
foreach (AccessListEntry entry in StorageApplicationPermissions.FutureAccessList.Entries)
{
StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(entry.Token);
}
答案 1 :(得分:0)
我最终设法让它发挥作用:
我增加了一个变量并使这个变量成为DataCompositeValue的键...... item.FolderRelativeId
似乎有一些特殊/禁止的字符。
List<StorageFolder> folders = new List<StorageFolder>();
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// ...
Windows.Storage.ApplicationDataCompositeValue data = new Windows.Storage.ApplicationDataCompositeValue();
var i = 0;
foreach (var item in folders)
{
if (item.Path == null || item.Path == "")
continue;
data[i.ToString()] = item.Path; // this is the line where I get the exception
i = i + 1;
}
localSettings.Values["folders"] = data;