2017-01-26 8 views
1

私は自分のストレージに保存されているファイルをドキュメントライブラリにエクスポートできるUWPアプリケーションを作ろうとしています。私は次の行を挿入しましたUWPファイルと画像ライブラリの保存

Package.appxmanifestで

<uap:Capability Name="picturesLibrary" /> 
<uap:Capability Name="documentsLibrary" /> 

パスを取得するコードは、このです:

StorageFolder storageFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.DocumentsLibrary);    
string path = storageFolder.Path + "\\" + fileName; 

ファイルを保存するためのコードはこれです:

FileStream writer = new FileStream(filePath, FileMode.Create); 

この時点で、この例外が発生します。

私950XLで
Access to the path 'C:\Users\luca9\AppData\Roaming\Microsoft\Windows\Libraries\Documents.library-ms' is denied. 

、例外は似ています:

Access to the path 'C:\Data\Users\DefApps\APPDATA\ROAMING\MICROSOFT\WINDOWS\Libraries\Documents.library-ms' is denied. 

私は、ドキュメントとピクチャライブラリの両方にtryiedましたが、私は同じ例外を取得します。

どうすれば解決できますか?

はパスで のFileStreamを得ることはありません、事前に

+0

は、あなたがこれらの記事を読むことがありますか? https://msdn.microsoft.com/en-us/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries .... https://msdn.microsoft .com/en-us/windows/uwp/files/file-access-permissions – JuP

+0

私はそれらを逃したと思います。どうもありがとうございます – lukemols

答えて

4

ルカをありがとう - アプリが権限を持っていません。すでにStorageFolderを持っているとして、例えば、StorageFileを作成し、その方法の一つで、それからのストリームを得るためにそれを使用します。

var file = await storageFolder.CreateFileAsync("fileName"); 
using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) 
{ 
    // do what you want 
}