Windows 7 新特性 Shell Library 编程接口介绍
2009-09-04 00:00:00 来源:WEB开发网C# ListFoldersInShellLibrary
using (ShellLibrary library = ShellLibrary.Load(libraryName, false))
{
/**//////////////////////////////////////////////////////////////////
// List all folders in the library.
//
foreach (ShellFolder folder in library)
{
Console.WriteLine(folder);
}
}
删除一个Shell Library
C++ DeleteShellLibrary
/**//*!
* Delete the shell library under the user's Libraries folder according to the
* specified library name.
*
* \param pwszLibraryName
* The name of the shell library to be deleted.
*/
BOOL DeleteShellLibrary(LPWSTR pwszLibraryName)
{
/**//////////////////////////////////////////////////////////////////////////
// Get the shell item that represents the library and its full path.
//
IShellItem2* pShellItem = GetShellLibraryItem(pwszLibraryName);
// Get the file-system full path of the shell item
LPWSTR wszLibraryFullPath;
pShellItem->GetString(PKEY_ParsingPath, &wszLibraryFullPath);
/**//////////////////////////////////////////////////////////////////////////
// Delete file with the library file-system based full path.
//
BOOL bSuccess = DeleteFileW(wszLibraryFullPath);
// Clean up
CoTaskMemFree(wszLibraryFullPath);
if (pShellItem != NULL)
pShellItem->Release();
return bSuccess;
}
C# DeleteShellLibrary
/**//////////////////////////////////////////////////////////////////////
// Delete the shell library.
//
string librariesPath = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),
ShellLibrary.LibrariesKnownFolder.RelativePath);
string libraryPath = Path.Combine(librariesPath, libraryName);
string libraryFullPath = Path.ChangeExtension(libraryPath, "library-ms");
File.Delete(libraryFullPath);
更多关于Windows 7 Shell Library的操作请参见CppWin7ShellLibrary, CSWin7ShellLibrary和VBWin7ShellLibrary示例。
更多精彩
赞助商链接