4

How do I open a Windows 7 Library like Documents, Pictures, Music, Videos and all other custom libraries from my app?

Libraries

I tried opening explorer.exe Libraries\Documents but it doesn't work.

Deanna
  • 23,876
  • 7
  • 71
  • 156
Elmo
  • 6,409
  • 16
  • 72
  • 140

6 Answers6

5

Find the AppData directory:

Dim appData As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Find the documents shortcut and open it in explorer:

For Each file As String In Directory.GetFiles(appData, "Documents.library-ms", SearchOption.AllDirectories)
    Process.Start(file)
Next
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
4

Look at this to see how the most common actions are performed on Windows 7 libraries.

Edit:

The sample uses the Windows API Code Pack for Micorosoft .Net Framework [ edit 2015-09-24: previous link is dead - use this SO entry to locate the necessary Nuget packages ] (thanks MarkJ for pointing out that the link should be there).

As for David Heffernan's question ...

You use the assign the ShellLibrary object to the DefaultDirectoryShellContainer property of an Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog (e.g. the Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog).

Community
  • 1
  • 1
AxelEckenberger
  • 16,628
  • 3
  • 48
  • 70
  • +1 for using a [proper API](http://archive.msdn.microsoft.com/WindowsAPICodePack) rather than relying on implementation details – MarkJ Jan 25 '12 at 12:39
  • 1
    The problem with this is that it's not obvious, to me at least, how you would open an explorer at this folder – David Heffernan Jan 25 '12 at 12:41
  • @Obalix Programmer wants to open an explorer.exe window at a specific library, not a file dialog. – David Heffernan Jan 25 '12 at 15:40
  • @DavidHeffernan: execute "%appdata%\Microsoft\Windows\Libraries\Documents.library-ms" on command line to open Documents library. – AxelEckenberger Jan 25 '12 at 16:18
  • The link to "Windows API Code Pack for Microsoft .Net Framework" is broken. There is another SO post about this here: http://stackoverflow.com/questions/24081665/windows-api-code-pack-where-is-it – Chris Sep 23 '15 at 18:21
1

Libraries are stored in C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Libraries and have the extension .library-ms so Documents would be Documents.library-ms

Elmo
  • 6,409
  • 16
  • 72
  • 140
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
  • 4
    Ooh, hard coded paths and reliance on implementation details. – David Heffernan Jan 25 '12 at 10:10
  • I was just telling them why it wasn't working, its not necessarily the correct way to program it, they were trying to open Libraries\Documents when it should be Libraries\Documents.library-ms – Iain Simpson Jan 25 '12 at 10:14
1

The Windows API Code Pack provides managed APIs to interact with Windows 7 libraries. I think it might help.

madd0
  • 9,053
  • 3
  • 35
  • 62
  • +1 Although it still looks tricky to use. Code samples [here](http://blogs.msdn.com/b/msaleh/archive/2009/08/26/windows-shell-programming-with-windows-api-code-pack.aspx) including one to iterate libraries. – MarkJ Jan 25 '12 at 12:34
  • Just noticed Obalix's answer also links to usage of this API code pack. He links [here](http://www.codeproject.com/Articles/65535/Windows-7-Libraries-C-Quick-Reference) – MarkJ Jan 25 '12 at 12:37
0

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

Replace MyDocuments with what ever folder you need, look in the enum to see which ones there are.

Captain Coder
  • 798
  • 5
  • 12
0

This is in relation to the comments under LostInLib 's post, as the explanation is too long to put as a comment.

You need to understand the difference between libraries and the documents folder as they are not the same thing. C:\Users\USERNAME\Documents is the default documents folder C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Libraries\Documents.library-ms is the library named Documents, the library is an index of all the locations you add to it, it doesn't have to be linked to C:\Users\USERNAME\Documents , for example on my network I have it set to \server\users\USERNAME , so when users go to the documents library on the start menu they are redirected to the server share. You can also have more than one location in a library so I could have my docs LOCAL in there AND the server my docs, so when I went to the my docs library it would show both folders in one place, so they would appear to be in the same my docs folder.

So presuming my docs is going to be here is not good as it doesn't have to be C:\Users\USERNAME\Documents , in the same way libraries also dont have to be here C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Libraries\Documents.library-ms if you redirect your appdata folder e.g like on a network your libraries can also be here : \server\users\USERNAME\AppData\Roaming\Microsoft\Windows\Libraries\Documents.library-ms

Iain Simpson
  • 8,011
  • 13
  • 47
  • 66