Open a Windows 7 Library in Windows Explorer

前端 未结 6 992
星月不相逢
星月不相逢 2020-12-21 02:10

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

相关标签:
6条回答
  • 2020-12-21 02:26

    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

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

    0 讨论(0)
  • 2020-12-21 02:32

    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).

    0 讨论(0)
  • 2020-12-21 02:34

    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

    0 讨论(0)
  • 2020-12-21 02:43

    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
    
    0 讨论(0)
  • 2020-12-21 02:43

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

    0 讨论(0)
  • 2020-12-21 02:44

    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

    0 讨论(0)
提交回复
热议问题