如何保存 StorageFile 以备后用? [英] How can I save a StorageFile to use later?

查看:38
本文介绍了如何保存 StorageFile 以备后用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WinRT 中工作,但有点卡住了:

I am working in WinRT, and I am kind of stuck:

我正在编写具有媒体库功能的音乐播放器.我在 SQLite 数据库中保存有关音乐的信息(例如艺术家等).我想让用户把他的音乐保存在他想要的任何地方,而不是 Windows 的方式,所有的东西都必须放在音乐"库中.

I am writing a music player with a media library capability. I keep information about the music (such as artists etc) in a SQLite database. I wanted to let the user keep his music anywhere he wants to, instead of the windows way, where it all has to be in the 'Music' library.

用户可以使用文件夹选择器在文件夹内添加音乐.我的问题是:我以后如何访问这些文件,例如在应用程序重新启动后?

Users can add the music inside folders using a folder picker. The problem I have is this: how can I access these files later, e.g after the application restarts?

保留路径不起作用,因为我总是收到拒绝访问"错误.我唯一可以访问文件的时间是使用浏览文件夹时获得的 StorageFile 对象.

Keeping the path doesn't work, since I always get "Access Denied" errors. The only time I can access the files is using the StorageFile objects I get from browsing the folder.

我该如何解决这个问题?

How can I solve this issue?

推荐答案

在已经给出的评论中,Windows.Storage.AccessCache (http://msdn.microsoft.com/en-us/library/windows/apps/br230566.aspx) 是您需要为此使用的 API.但是,不是保存对每个单独 StorageFile 的访问权限,而是使用文件夹选择器并保存 StorageFolder 对象的权限(API 对两者都适用).您不太可能达到文件夹的 1000 个项目限制.

As in the comments already given, the Windows.Storage.AccessCache (http://msdn.microsoft.com/en-us/library/windows/apps/br230566.aspx) is the API you need to use for this. However, instead of saving access to each individual StorageFile, use the folder picker and save permissions for the StorageFolder object instead (the API works for both). It's unlikely that you'll hit the 1000 item limit for folders.

这篇关于如何保存 StorageFile 以备后用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆