1

我有一个方法可以返回文件的正确路径

    StorageFile newFile = null;
        try
        {
            string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
            newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
        }
        catch (FileNotFoundException) { newFile = null; }
        if (newFile == null)
        {
            string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
            StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
            newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
        }
        if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
        return newFile.Path;

但是,有时我会遇到错误

    StorageFile.GetFileFromPathAsync(pth).GetResults()

抛出的错误是:

   StorageFile newFile = null;
        try
        {
            string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
            newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
        }
        catch (FileNotFoundException) { newFile = null; }
        if (newFile == null)
        {
            string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
            StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
            newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
        }
        if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
        return newFile.Path;

我究竟做错了什么?我是 c# 和线程的新手,这个错误让我很生气,因为有时它有效,有时却无效。请帮忙!

4

1 回答 1

-2

运行时应用程序中没有权限!您无法使用此方法访问文件。检查此页面

于 2017-03-24T02:42:12.120 回答