Нотатка
Доступ до цієї сторінки потребує авторизації. Можна спробувати ввійти або змінити каталоги.
Доступ до цієї сторінки потребує авторизації. Можна спробувати змінити каталоги.
Windows Vista introduces new storage scenarios and a new user profile namespace. To address these new factors, the older system of referring to standard folders by a CSIDL value has been replaced. As of Windows Vista, those folders are referenced by a new set of GUID values called Known Folder IDs.
The Known Folder system provides these advantages:
- Independent software vendors (ISVs) can extend the set of Known Folder IDs with their own. They can define folders, give them IDs, and register them with the system. CSIDL values could not be extended.
- All Known Folders on a system can be enumerated. No API provided this functionality for CSIDL values. See IKnownFolderManager::GetFolderIds for more information.
- A known folder added by an ISV can add custom properties that allow it to explain its purpose and intended use.
- Many known folders can be redirected to new locations, including network locations. Under the CSIDL system, only the My Documents folder could be redirected.
- Known folders can have custom handlers for use during creation or deletion.
The CSIDL system and APIs that make use of CSIDL values are still supported for compatibility. However, it is not recommended to use them in any new development.
Important
For new code, always use SHGetKnownFolderPath with KNOWNFOLDERID constants. The older SHGetFolderPath and CSIDL values are deprecated and should not be used in new applications.
When calling SHGetKnownFolderPath:
- You must call CoInitializeEx before using this function (COM must be initialized on the calling thread).
- You must free the returned string with CoTaskMemFree when done. Failure to do so causes a memory leak.
- For .NET applications, use Environment.GetFolderPath or Windows.Storage.KnownFolders (WinRT) instead of P/Invoking shell functions directly.
The following topics discuss the specifics of the Known Folders system.
- Working with Known Folders in Applications
- How to Extend Known Folders with Custom Folders
- KNOWNFOLDERID
The following reference pages explain the Win32 Known Folders functions, which can be used to retrieve the location of Known Folders or redirect them to a new location. These functions replace older Win32 functions. The new functions are provided to give equivalent behavior to the old functions, but each new function is also duplicated by a Component Object Model (COM) API.
| New Function | Replaces | COM Equivalent |
|---|---|---|
| SHGetKnownFolderPath | SHGetFolderPath | IKnownFolder::GetPath |
| SHGetKnownFolderIDList | SHGetFolderLocation | IKnownFolder::GetIDList |
| SHSetKnownFolderPath | SHSetFolderPath | IKnownFolder::SetPath |
The following reference pages explain the COM Known Folders APIs, which provide all of the functionality of the Win32 APIs listed above, plus add the ability to enumerate all Known Folders, access Known Folder properties, and extend the standard set of Known Folders.
A C++ sample that demonstrates the Known Folder APIs is included in the Windows Software Development Kit (SDK). Once you have installed the Windows SDK on your computer, the sample can be found under %ProgramFiles%\Microsoft SDKs\Windows\v6.0\Samples\WinUI\Shell\AppPlatform\KnownFolders.