2017-09-20 4 views
-1

ネットワークドライブ(\\またはマップされている)にあるMusicLibrary KnownFolderに私のUWPアプリケーションがアクセスしています。ネットワークロケーションのMusicLibraryがUnauthorizedAccessExceptionをスローする

ミュージックライブラリのファイルをWindowsから直接編集しても問題はありませんが、アプリケーションがファイル(この場合はタグ)を編集しようとするとUnauthorizedAccessExceptionがスローされます。私がMusicLibraryをローカルフォルダに入れ替えると、すべてが大変なことになります。

ミュージックライブラリとプライベートネットワークの機能を選択しました。

誰もこのようなことに遭遇しましたか?

アップデート1: 関係のない

更新2(更新):

はやや簡潔に私のために、この問題を複製する例については以下を参照してください。私は便宜のためにボタンでそれをつけた。どうやらこれはMediaPlayerに関連していた、私は当時気づいていなかった。

MediaLibraryがローカルディレクトリ、たとえばC:\ Musicに設定されている場合、正常に動作します。遠隔地に設定すると、X:\ HomeServerShares \ Musicと言うと例外がスローされます。

Gitリポジトリ:https://github.com/Rekrii/UWPMusicLibAccessDeniedExample

private async void Button_Click(object sender, RoutedEventArgs e) 
     { 
      //Get a list of files from the music library 
      IReadOnlyList<StorageFile> files = await KnownFolders.MusicLibrary.GetFilesAsync(); 
      //Select random file from the music library 
      //using GetFileFromPathAsync as per comment below 
      StorageFile infoFile = 
       await StorageFile.GetFileFromPathAsync(
        files[new Random().Next(0, files.Count - 1)].Path); 

      //Create a MediaSource and add it to a MediaPlaybackList 
      MediaSource source = MediaSource.CreateFromStorageFile(infoFile); 
      MediaPlaybackList list = new MediaPlaybackList(); 
      list.Items.Add(new MediaPlaybackItem(source)); 

      //Create a MediaPlayer and add the MediaPlaybackList to it 
      MediaPlayer player = new MediaPlayer(); 
      player.Source = list; 
      //'mediaPlayer' was created in xaml: <MediaPlayerElement x:Name="mediaPlayer"/> 
      mediaPlayer.SetMediaPlayer(player); 

      //Get the music properties of the audio file 
      MusicProperties musicProperties = await infoFile.Properties.GetMusicPropertiesAsync(); 
      //Edit them (so UWP will attempt to edit the file) 
      musicProperties.Title = "woo"; 
      //Save the properties... 
      //When using C:\etc as a MusicLibrary, this will work fine 
      //When using a mapped location say X:\etc this save will thorw access denied 
      await musicProperties.SavePropertiesAsync(); 
     } 

私はネットワークドライブにアクセスしているユーザーがフルコントロール権限を持っていることを確認しているが、フォルダの所有者であり、エクスプローラからファイルを編集することができます。

名前を変更するのは編集とほぼ同じであるため、C#でファイルの名前を変更して正しくアクセスできるようにすることもできます。私が使用している 'パス'は、X:\などの形式であり、X:\はマップされた文字です。

SavePropertiesAsyncコールにエラーが発生することがありますか?

+0

Package.appxmanifestで機能を設定しましたか? – Isma

+0

@Isma Yep。両方ともVSで、ファイルをチェックしてください(確かめてください)。 – Incipient

+1

ネットワークロケーションのMusicLibraryにはどのようにアクセスしますか?問題を再現できる[MCVE]を共有できますか? –

答えて

0

enter image description here

汎用名前付け規則(UNC)は、一般に、共有ネットワークフォルダにアクセスするためのMicrosoft Windowsで使用されるネーミングシステムです。詳細は、を参照してください。

これは私のPackage.appxmanifestです:

<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="UWP_how_to_show_image_from_a_network.App"> 
    <uap:VisualElements DisplayName="UWP how to show image from a network" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="UWP how to show image from a network" BackgroundColor="transparent"> 
     <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"> 
     </uap:DefaultTile> 
     <uap:SplashScreen Image="Assets\SplashScreen.png" /> 
    </uap:VisualElements> 
    <Extensions> 
     <uap:Extension Category="windows.fileTypeAssociation"> 
     <uap:FileTypeAssociation Name="mymusictest"> 
      <uap:DisplayName>MyMusicTest</uap:DisplayName> 
      <uap:SupportedFileTypes> 
      <uap:FileType>.mp3</uap:FileType> 
      </uap:SupportedFileTypes> 
     </uap:FileTypeAssociation> 
     </uap:Extension> 
    </Extensions> 
    </Application> 
</Applications> 
<Capabilities> 
    <Capability Name="internetClient" /> 
    <Capability Name="internetClientServer" /> 
    <Capability Name="privateNetworkClientServer" /> 
    <uap:Capability Name="enterpriseAuthentication" /> 
</Capabilities> 

それは、UnauthorizedAccessExceptionを投げないであろうと、我々はStorageFolder.GetFolderFromPathAsyncの方法でフォルダを取得することができます。

+0

私は上記のmp3ファイルタイプdecと同様の機能を使用しました。 GetFileFrompathAsyncを使うようにGitHubファイルを更新しました。ネットワークにアクセスするユーザーは、ファイル所有者でもフルコントロールのアクセス許可もあり、エクスプローラからファイルを編集できます。 – Incipient

+0

名前を変更するのは編集とほぼ同じであるため、C#でファイルの名前を変更して正しくアクセスできるようにすることもできます。私が使用している 'パス'は、X:\などの形式であり、X:\はマップされた文字です。 – Incipient

関連する問題