程序用VS2011调试,运行,都正常.但是打包后安装运行,却提示没有文件访问权限不足异常.
最后定位到
Uri newUri = new Uri(new Uri(file.Path), gryfileName);
//指向安装包里的某个文件
StorageFile gryFile = await StorageFile.GetFileFromPathAsync(newUri.AbsolutePath.Replace('/', '\\'));
因为用VS2011直接deploy,路径是project\bin\xxxxxxxxxxxxxx,权限要求比较低,而打包后安装的路径是C:\Program Files\WindowsApps\XXXXXXXXX,需要一定的权限.
把代码改成
StorageFile gryFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(gryFileName);
后问题解决.
教训:不能乱用API啊.