I'm trying to get default music library folder path in Windows Universal App written in C#. However,
<uap:Capability Name="musicLibrary" />
In the Remarks of KnownFolders.MusicLibrary property, we can find that
Libraries let users view related content in a single location. A library is a virtual folder. The folders in a library remain in their original locations. Learn more about libraries in Windows Libraries.
StorageFolder.Path property can get the full path of the current folder in the file system, but only if the path is available. As Music Library is a virtual folder, the file system path is not available. So it always returns empty string.
The Music Library typically has the following path.
This is the path of the known folder included in Music Library.
A library is a virtual collection of folders, which includes a known folder by default plus any other folders the user has added to the library by using your app or one of the built-in apps. For example, the Pictures library includes the Pictures known folder by default. The user can add folders to, or remove them from, the Pictures library by using your app or the built-in Photos app.
To get this path, we can use StorageLibrary class. This class lets us add and remove folders from a library like Music or Videos and lets us get a list of folders included in the library.
The known folder is the folder in a library where new files are saved by default. We can use StorageLibrary.SaveFolder property to get this folder and than get its path like following:
var musicLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Music); Debug.WriteLine(musicLibrary.SaveFolder.Path);
For more info, please see Files and folders in the Music, Pictures, and Videos libraries.