Get the Path to Windows XP Special Folders

The Designed for Windows XP Application Specification requires that your application store user created files in the My Documents, My Pictures or My Music (or descendant) folders and data that is used by the application in the Application Data folder.

It also states that the only acceptable way to determine these folders is via the SHGetFolderPath API exported by SHFolder.dll. This sample shows how to use this DLL to retrieve paths to these and other Special Folders.

Determine the location of Windows Special Folders using SHGetFolderPath API from SHFolder.dll.
Download Source Code

Description

SHGetFolderPath exported from SHFolder.dll behaves the same on all Windows platforms (Win95, Win98, Win98SE, WinME, Win2K, WinXP). It is included in some Operating Systems but is available as a redistributable component and is included with this sample. You should distribute it with your application and place it in the System folder on the target machine. It supports many but not all Special Folders. To learn how to get the path to the unsupported special folders see my Create Desktop Shortcuts sample.

Special Folders are identified by a CSIDL which is passed as a parameter to the SHGetFolderPath API. Also passed in is a flag indicating if the API should return the folder's current path (i.e. if the folder was renamed or moved by the user) or the default path. If the folder does not exists, you can have SHGetFolderPath create it by ORing the CSIDL with the CSIDL_FLAG_CREATE flag. Finally the API returns the path as a parameter and a return code which indicates the call's status.

Using the API to retrieve the paths to these folders is simple and the only valid way to do it. See the sample code for more details.

Instructions

Download the project and press F5 to run the program. Select a folder from the listbox. The full path will be displayed.


About TheScarms
About TheScarms


Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page


© Copyright 2016 TheScarms
Goto top of page