Vincent Dagpin
Vincent Dagpin

Reputation: 3611

Get all directories within an Explorer Library

How can I get all the library locations added to My Music?

For this example, I have added these directories to the library:

E:\My Music
E:\Mp3

I tried:

Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);

But it returns:

C:\Users\MyUser\Music

Upvotes: 10

Views: 988

Answers (3)

mdiehl13
mdiehl13

Reputation: 492

I did something similar and posted a full solution with code using Windows API Code Pack at this other StackOverflow question. In your case, you would find the code that says:

        ICollection<IKnownFolder> allSpecialFolders = Microsoft.WindowsAPICodePack.Shell.KnownFolders.All;

And then iterate over these folders to find the one that matches your need:

    string fpath = "";
    // Iterate over each folder and find the one we want
    foreach ( var folder in allSpecialFolders )
    {
        if ( folder.ParsingName == foldername )
        {
            // We now have access to the xml path
            fpath = folder.Path;
        }
    }

    if ( fpath == "" )
        return null;

    var intFolders = GetLibraryInternalFolders(fpath);

    return intFolders.Folders.ToList();

And then use the GetLibraryInternalFolders() function to return the multiple folders inside that. Anyway, check out my full-code solution at the other question.

Upvotes: 0

Francesco De Lisi
Francesco De Lisi

Reputation: 1523

Are you trying to develop a Windows Store Application? If yes, try with the Windows.Store library as suggested here

MSDN: http://msdn.microsoft.com/it-it/library/windows/apps/windows.storage.knownfolders.musiclibrary

Upvotes: 1

Rikki
Rikki

Reputation: 646

Any libraries added to Media Player should end up in the AppData directory.

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\Libraries\Music.library-ms"

Maybe this will help.

Upvotes: 1

Related Questions