Subhankar
Subhankar

Reputation: 507

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. enter image description here

Upvotes: 0

Views: 357

Answers (3)

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.

Upvotes: 1

Ricky
Ricky

Reputation: 2374

You can access the contents of users folder like this:

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

Upvotes: 1

Typist
Typist

Reputation: 1474

Use SpecialFolder to get the user folder and Directory.Enumerate() for getting files in the folder.

Upvotes: 0

Related Questions