简体   繁体   English

在Windows资源管理器中打开Windows 7库

[英]Open a Windows 7 Library in Windows Explorer

How do I open a Windows 7 Library like Documents , Pictures , Music , Videos and all other custom libraries from my app? 如何从我的应用程序中打开DocumentsPicturesMusicVideos和所有其他自定义库等Windows 7库?

图书馆

I tried opening explorer.exe Libraries\\Documents but it doesn't work. 我尝试打开explorer.exe Libraries\\Documents但它不起作用。

Find the AppData directory: 找到AppData目录:

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

Look at this to see how the most common actions are performed on Windows 7 libraries. 请查看此内容 ,了解如何在Windows 7库上执行最常见的操作。

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). 该示例使用适用于Micorosoft .Net FrameworkWindows API代码包 [编辑2015-09-24:以前的链接已死 - 使用此SO条目查找必要的Nuget包] (感谢MarkJ指出链接应该在那里) 。

As for David Heffernan 's question ... 至于大卫·赫弗南的问题......

You use the assign the ShellLibrary object to the DefaultDirectoryShellContainer property of an Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog (eg the Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog ). 您使用将ShellLibrary对象分配给Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogDefaultDirectoryShellContainer属性(例如Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog )。

库存储在C:\\Users\\USERNAME\\AppData\\Roaming\\Microsoft\\Windows\\Libraries ,扩展名为.library-ms因此Documents将为Documents.library-ms

The Windows API Code Pack provides managed APIs to interact with Windows 7 libraries. Windows API代码包提供托管API以与Windows 7库进行交互。 I think it might help. 我认为这可能会有所帮助。

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

将MyDocuments替换为您需要的文件夹,查看枚举以查看其中的文件夹。

This is in relation to the comments under LostInLib 's post, as the explanation is too long to put as a comment. 这与LostInLib的帖子中的评论有关,因为解释时间太长而无法作为评论。

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. C:\\ Users \\ USERNAME \\ Documents是默认文档文件夹C:\\ Users \\ USERNAME \\ AppData \\ Roaming \\ Microsoft \\ Windows \\ Libraries \\ Documents.library-ms是名为Documents的库,该库是所有位置的索引你添加它,它不必链接到C:\\ Users \\ USERNAME \\ Documents,例如在我的网络上我将它设置为\\ server \\ users \\ USERNAME,所以当用户转到文档库时开始菜单将它们重定向到服务器共享。 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. 您还可以在库中拥有多个位置,这样我就可以在我的文档中使用本地文档和服务器我的文档,所以当我访问我的文档库时,它会在一个地方显示两个文件夹,所以它们看起来像是在我的docs文件夹中。

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 eg like on a network your libraries can also be here : \\server\\users\\USERNAME\\AppData\\Roaming\\Microsoft\\Windows\\Libraries\\Documents.library-ms 所以假设我的文档将在这里不好,因为它不必是C:\\ Users \\ USERNAME \\ Documents,同样的方式库也不必在这里C:\\ Users \\ USERNAME \\ AppData \\ Roaming \\ Microsoft \\ Windows \\ Libraries \\ Documents.library-ms如果你重定向appdata文件夹,例如在网络上你的库也可以在这里:\\ server \\ users \\ USERNAME \\ AppData \\ Roaming \\ Microsoft \\ Windows \\ Libraries \\ Documents.library -女士

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM