如何從我的應用程序打開Windows 7庫,如Documents
,Pictures
,Music
,Videos
和所有其他自定義庫?在Windows資源管理器中打開Windows 7庫
我試圖打開explorer.exe Libraries\Documents
但它不工作。
如何從我的應用程序打開Windows 7庫,如Documents
,Pictures
,Music
,Videos
和所有其他自定義庫?在Windows資源管理器中打開Windows 7庫
我試圖打開explorer.exe Libraries\Documents
但它不工作。
找到AppData目錄:
Dim appData As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
查找的文件快捷方式,並在資源管理器中打開它:
For Each file As String In Directory.GetFiles(appData, "Documents.library-ms", SearchOption.AllDirectories)
Process.Start(file)
Next
這也看起來像它依賴於實現細節。肯定有這個API。 –
@大衛有一個適當的API和Obalix已經在他的答案中鏈接到它。 – MarkJ
庫儲存在C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Libraries
和具有擴展.library-ms
所以Documents
將Documents.library-ms
哦,硬編碼路徑和對實現細節的依賴。 –
我只是告訴他們爲什麼它不工作,它不一定是正確的編程方式,他們試圖打開Libraries \ Documents時,它應該是庫\ Documents.library-ms –
查看this以查看Windows 7庫上最常見的操作是如何執行的。
編輯:
該示例使用Windows API Code Pack for Micorosoft .Net Framework[編輯2015年9月24日:一個鏈接是死的 - 使用this SO entry找到必要的NuGet包](感謝MarkJ指點該鏈接應該在那裏)。
至於David Heffernan的問題...
您可以使用分配ShellLibrary
對象的Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog
的DefaultDirectoryShellContainer
特性(例如在Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog
)。
使用[適當的API](http://archive.msdn.microsoft.com/WindowsAPICodePack)+1而不是依靠實現細節 – MarkJ
問題在於它對於我來說至少不是顯而易見的,至少,在這個文件夾下打開一個資源管理器 –
@DavidHeffernan:見編輯。 – AxelEckenberger
Windows API Code Pack提供託管API與Windows 7庫進行交互。我認爲這可能會有所幫助。
這是關係到下LostInLib的文章的評論,因爲對此的解釋是太長以至於不能作爲評論。
您需要了解庫和文檔文件夾之間的區別,因爲它們不是同一件事。 C:\ Users \ USERNAME \ Documents是默認文檔文件夾C:\ Users \ USERNAME \ AppData \ Roaming \ Microsoft \ Windows \ Libraries \ Documents.library-ms是名爲Documents的庫,該庫是所有位置的索引您添加到它,它不必鏈接到C:\ Users \ USERNAME \ Documents,例如在我的網絡上,我已將它設置爲\ server \ users \ USERNAME,因此當用戶轉到文檔庫上開始菜單,他們被重定向到服務器共享。您也可以在一個庫中擁有多個位置,這樣我就可以將我的文檔LOCAL和服務器中的文檔關聯起來,因此,當我訪問我的文檔庫時,它會在一個位置顯示這兩個文件夾,因此它們似乎是在我的文檔文件夾中。
因此,假設我的文檔將在這裏不是很好,因爲它不一定是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-ms
請參閱http://www.codeproject.com/Articles/65535/Windows-7-Libraries-C-Quick-Reference – ken2k