Quickstart: Managing folders in the Music, Pictures, and Videos libraries (XAML)
Add existing folders of music, pictures, or videos to the corresponding libraries. You can also remove folders from libraries, and get the list of folders in a library.
Understand async programming for Windows Runtime apps using C++, C#, or Visual Basic.
You can learn how to write asynchronous apps in Quickstart: Calling asynchronous APIs in C# or Visual Basic.
Select the required capability in the app manifest file.
In Visual Studio, open the app manifest file in Manifest Designer. On the Capabilities page, select the libraries that your app manages.
- Music Library
- Pictures Library
- Videos Library
Import the Windows.Storage namespace in your code.
At the top of each class file that uses the methods and properties described in this topic, add the following line of code:
To get a reference to the user's Music, Pictures, or Video library, select the corresponding capability in the app manifest file, and then call the StorageLibrary.GetLibraryAsync method. Provide the corresponding value from the KnownLibraryId enumeration.
To get the list of folders in a library, get the value of the StorageLibrary.Folders property.
To get the folder in a library where new files are saved by default, get the value of the StorageLibrary.SaveFolder property.
To open a folder picker and let the user select an existing folder to add to a library, call the StorageLibrary.RequestAddFolderAsync method. There are no options to customize the picker.
To remove a folder from a library, call the StorageLibrary.RequestRemoveFolderAsync method and specify the folder to be removed.
Before you call the RequestRemoveFolderAsync, you can get the list of folders in the library from the Folders property of the library. Then you can display the list of folders in a ListView control or a similar control, and let the user select the folder to remove.
The following example assumes that the user has selected the folder to remove from a ListView control named lvPictureFolders.
StorageFolder folderToRemove = (StorageFolder)lvPictureFolders.SelectedItem; bool result = await myPictures.RequestRemoveFolderAsync(folderToRemove);
To get notified about changes to the list of folders in a library, register a handler for the StorageLibrary.DefinitionChanged event of the library.
To learn more about working with folders and files, see the following topics:
- Quickstart: Accessing files programmatically
- Quickstart: Reading and writing files
- Quickstart: Accessing files with file pickers