简体   繁体   中英

How can I access files inside My User folder from the application?

I am creating an Windows Explorer kind of app using metro UI. I want to show content of a certain folder in my User folder.

I wanted to know if it is possible to access the folders and files inside users folder and how do I do it?

Edit :

I tried using StorageFolder. For documents folder, it gives me an exception. 在此处输入图片说明

您可以像这样访问users文件夹的内容:

string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)).ToString();

The KnownFolders.DocumentsLibrary folder has restrictions on its use. You have to manually declare the capability in your manifest, declare specific file types you want to access, and then to publish the app in the Store you have to be using a company account (not an individual account), and have to submit written justification for your programmatic use of the folder.

See http://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx as well as the note for section 6.6 of http://msdn.microsoft.com/en-us/library/windows/apps/hh921583.aspx .

Note that this is for programmatic access without user consent. If you use the file picker, the user can of course point to the documents folder thereby giving you permission to use it. But without that, you need to use your app data folders where you do have programmatic access.

The underlying reasoning here is that files that your app it generating for its own use, that don't have direct meaning to the user, should go in app data to avoid polluting a folder like Documents with stuff that the user doesn't know what to do with. For "user data" files--which the user does understand, you should give them the option to choose where those files go, hence the use of the file picker.

A few file types like music, pictures, and video have direct library access via manifest capabilities, but in that case the user generally understands that they're working with that kind of data.

使用SpecialFolder来获取用户文件夹,并使用Directory.Enumerate()来获取文件夹中的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM