【问题标题】:Windows 8 GetFileAsync method gives UnAuthorized errorWindows 8 GetFileAsync 方法给出未经授权的错误
【发布时间】:2014-04-15 12:14:35
【问题描述】:

以下代码尝试从 MusicLibrary 获取 Mp3 文件

它给了我,

A first chance exception of type 
'System.UnauthorizedAccessException'
occurred in AccessingPictures.exe

这是我的代码:

public async void getFile()
{
    StorageFolder folder = KnownFolders.MusicLibrary;

    try
    {
        sampleFile = await folder.GetFileAsync("Test1.mp3");
    }
    catch (FileNotFoundException e)
    {
        // If file doesn't exist, indicate users to use scenario 1
        Debug.WriteLine(e);
    }
}

private void btnRead_Click(object sender, RoutedEventArgs e)
{
    getFile();
}

我们不能访问媒体文件吗?
我可以使用文件选择器来做到这一点。
但是当我尝试直接访问它时它不起作用。

我这里有什么遗漏吗?

【问题讨论】:

    标签: c# .net windows-8.1


    【解决方案1】:

    从相机胶卷中检索图片

     Void GetCameraPhotos()
          {
            using (var library = new MediaLibrary())
            {
    
                PictureAlbumCollection allAlbums = library.RootPictureAlbum.Albums;
                PictureAlbum cameraRoll = allAlbums.Where(album => album.Name == "Camera Roll").FirstOrDefault();
                var CameraRollPictures = cameraRoll.Pictures
    
            }
          }
    

    【讨论】:

    【解决方案2】:

    除非是响应用户请求,否则您无法访问这些文件。即用户必须点击按钮或其他东西,然后点击逻辑最终调用访问文件的代码。如果您想在之后获取该文件,则需要将其复制到应用程序的数据文件夹中。

    【讨论】:

    • 不。现在我被困在访问音乐文件上。我能够访问照片和视频....
    【解决方案3】:

    我终于想通了。这是因为我没有启用 Manifest 文件中的功能。

    它现在就像一个魅力。

    谢谢大家。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 2016-04-16
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      相关资源
      最近更新 更多