[英]How to export a file from the Assets folder to the phone's Documents folder in Windows Phone 8.1 RT?
[英]Windows Phone 8.1 access file in Documents folder
我是Windows手机开发的新手,不使用Silverlight或WPF。 我将文件“links.txt”复制到我的Windows Phone文件夹“\\ Documents \\”,我想访问并获取文件中的内容,但我收到了拒绝访问错误。 我点击Package.appxmanifest文件,然后选择“功能”选项卡,但我没有看到“文档库访问”供我查看。 事实上,我没有看到任何“...图书馆访问”显示。 以下是代码:
string fileName = "\\Documents\\links.txt";
string parentPath = ApplicationData.Current.LocalFolder.Path;
string filePath = Path.Combine(parentPath, fileName);
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath);
有什么建议我怎么读这个文件? 谢谢。
更新:
看起来上面的代码不起作用,但是当使用下面的代码并将文件夹更改为“Music”而不是“Documents”时,请检查“MusicLibrary”的功能,它正在运行。
var folder = KnownFolders.MusicLibrary;
var file = await folder.GetFileAsync("links.txt");
var read = await FileIO.ReadTextAsync(file);
谢谢!
如果您检查了需要文档Capability
,则应使用KnownFolders类而不是ApplicationData.Current.LocalFolder.Path
。
例如:
StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
StorageFile file = await storageFolder.CreateFileAsync("sample.dat", CreationCollisionOption.ReplaceExisting);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.