MiddleD.
MiddleD.

Reputation: 383

How to get a path to some special folders in windows universal apps without "Enviroment"

Usualy, to put some file to local directory on different devices (for example to mydocuments on some phone) we can get this directory using something like environment.getfolderpath(environment.specialfolder.mydocuments). But if I am right, this wouldn't work in windows-universal application (may be because of x-box), enviroment got only .GetEnviromentVariable(s).

So the question is - how can we get a path to some local directory on any windows-device (folders like mydocuments, applicationdata or the same, not temp or current directory or app-folder)?

Upvotes: 1

Views: 1443

Answers (1)

Alex
Alex

Reputation: 987

Please use KnownFolders class in Windows.Storage namespace. For example, to access the PictureLibrary use:

StorageFolder storageFolder = KnownFolders.PicturesLibrary;

StorageFolder in its turn has a read-only property Path. By you should rethink the entire concept of manipulating files with the new API.

For example, to create an image file, you would use the following:

StorageFile file =
    await storageFolder.CreateFileAsync("sample.png",
        CreationCollisionOption.ReplaceExisting);

You can find more examples on MSDN: KnownFolders class.

Upvotes: 3

Related Questions