10

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

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Vincent Dagpin
  • 3,581
  • 13
  • 55
  • 85
  • Can you just add the directory one by one manually if only two folders exist? – Tianyun Ling Apr 12 '13 at 01:59
  • 1
    i have lots of directory to add on my library location so adding it one by one is not an option for me.. :) – Vincent Dagpin Apr 12 '13 at 02:00
  • 2
    You got your work cut out for you, but here is a great example on how it's done. http://www.codeproject.com/Articles/143038/Parsing-Windows-7-Libraries-Without-NET-4-or-the-W – Mike Perrenoud Apr 12 '13 at 02:04
  • @MichaelPerrenoud thanks for the response, i'll review it. – Vincent Dagpin Apr 12 '13 at 02:07
  • I don't suppose it's sufficient to discover the path to the Music Library folder itself? You can do that using the [`SHGetKnownFolderPath` function](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx) and passing the value `FOLDERID_MusicLibrary`. Much easier than enumerating all of the folders *added* to the library, and should be sufficient for most uses. – Cody Gray - on strike Apr 12 '13 at 05:27
  • @MichaelPerrenoud Based on your link, it suggests that this is much easier to do with .NET 4 – Danny Beckett Apr 12 '13 at 06:57

3 Answers3

1

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.

Rikki B
  • 636
  • 8
  • 23
1

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

Community
  • 1
  • 1
Francesco De Lisi
  • 1,493
  • 8
  • 20
0

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.

Community
  • 1
  • 1
mdiehl13
  • 472
  • 6
  • 19