如何获得对文件文件夹(UWP)的访问权限 [英] How do I gain access to the documents folder (UWP)
问题描述
关闭UWP时,我将从数据库中获取项目列表.我想将此列表保存到将在documents文件夹中创建/编辑的文件中.
When closing the UWP I will get a list of items from a database. I want to save this list in a file which will be created/edited in the documents folder.
我试图通过以下方式访问Documents文件夹:
I tried to gain access to the Documents folder by this:
StorageFolder stFo = KnownFolders.DocumentsLibrary;
我的问题是我无权访问Documents文件夹(发生了类型为"System.UnauthorizedAccessException"的异常...".)
My Problem is that I have no access to the Documents Folder ('An exception of type "System.UnauthorizedAccessException" occured...').
现在我读到您可以通过在 Package.appxmanifest
Now I have read that you could get access by adding some lines to Package.appxmanifest
<Package xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
和
<Capabilities>
<rescap:Capability Name="appCaptureSettings"/>
<uap Name="documentsLibrary"/>
</Capabilities>
我试过了,但是没用.
还有另一种获取访问权限的方法吗?(如果是,那么它的例子太棒了)
Is there another way to gain access? (If yes, an example for it would be awesome)
编辑
这可能很重要:此UWP侧面加载
This is probably important: This UWP is sideloaded
推荐答案
仅添加声明 documentsLibrary
功能是不够的.您还需要向应用清单添加文件类型关联,以声明您的应用可以访问哪些特定文件类型:
It's not enough to add the declare the documentsLibrary
capability. You also need to add file type associations to your app manifest to declare what specific file types your app can access: https://social.msdn.microsoft.com/Forums/ie/en-US/7ee61fd7-db6d-49a6-bda4-701105a500e7/uwpcant-access-documents-library-in-universal-windows-app?forum=wpdevelop
请注意,尽管文档库不适合一般使用.
Note that the Documents library is not intended for general use though.
您应该考虑使用 ApplicationData.LocalFolder
或 LocalCacheFolder
, RoamingFolder
, SharedLocalFolder
或 TemporaryFolder
基于您的数据存储方式.
You should consider using ApplicationData.LocalFolder
or LocalCacheFolder
, RoamingFolder
, SharedLocalFolder
, or TemporaryFolder
based on how your data should be stored.
这篇关于如何获得对文件文件夹(UWP)的访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!