Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than shell32, prefix the name with the module name and a period.
SHGetFolderPath (shell32)
.
C# Signature:
[DllImport("shell32.dll")]
static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken,
uint dwFlags, [Out] StringBuilder pszPath);
VB.Net Signature:
<DllImport("shell32.dll")> _
Private Shared Function SHGetFolderPath(ByVal hwndOwner As IntPtr, ByVal nFolder As Int32, ByVal hToken As IntPtr, ByVal dwFlags As Int32, ByVal pszPath As StringBuilder) As Int32
End Function
C# struct for nFolder:
public enum SpecialFolderType
{
// Version 5.0. The file system directory that is used
// to store administrative tools for an individual user.
// The Microsoft Management Console (MMC) will save customized
// consoles to this directory, and it will roam with the user.
AdministrativeTools = 0x0030,
// Version 5.0. The file system directory containing
// administrative tools for all users of the computer.
CommonAdministrativeTools = 0x002f,
// Version 4.71. The file system directory that serves as
// a common repository for application-specific data.
// A typical path is C:\Documents and Settings\username\Application Data.
// This CSIDL is supported by the redistributable Shfolder.dll
// for systems that do not have the Microsoft Internet Explorer 4.0
// integrated Shell installed
ApplicationData = 0x001a,
// Version 5.0. The file system directory containing
// application data for all users. A typical path is
// C:\Documents and Settings\All Users\Application Data.
CommonAppData = 0x0023,
// The file system directory that contains documents
// that are common to all users. A typical paths is
// C:\Documents and Settings\All Users\Documents.
// Valid for Windows NT systems and Microsoft Windows 95 and
// Windows 98 systems with Shfolder.dll installed.
CommonDocuments = 0x002e,
// The file system directory that serves as a common repository
// for Internet cookies. A typical path is
// C:\Documents and Settings\username\Cookies.
Cookies = 0x0021,
// Version 5.0. Combine this CSIDL with any of the following CSIDLs
// to force the creation of the associated folder.
CreateFlag = 0x8000,
// The file system directory that serves as a common repository
// for Internet history items.
History = 0x0022,
// Version 4.72. The file system directory that serves as
// a common repository for temporary Internet files. A typical
// path is C:\Documents and Settings\username\Local Settings\Temporary Internet Files.
InternetCache = 0x0020,
// Version 5.0. The file system directory that serves as a data
// repository for local (nonroaming) applications. A typical path
// is C:\Documents and Settings\username\Local Settings\Application Data.
LocalApplicationData = 0x001c,
// Version 5.0. The file system directory that serves as
// a common repository for image files. A typical path is
// C:\Documents and Settings\username\My Documents\My Pictures.
MyPictures = 0x0027,
// Version 6.0. The virtual folder representing the My Documents
// desktop item. This is equivalent to CSIDL_MYDOCUMENTS.
// Previous to Version 6.0. The file system directory used to
// physically store a user's common repository of documents.
// A typical path is C:\Documents and Settings\username\My Documents.
// This should be distinguished from the virtual My Documents folder
// in the namespace. To access that virtual folder,
// use SHGetFolderLocation, which returns the ITEMIDLIST for the
// virtual location, or refer to the technique described in
// Managing the File System.
Personal = 0x0005,
// Version 5.0. The Program Files folder. A typical
// path is C:\Program Files.
ProgramFiles = 0x0026,
// Version 5.0. A folder for components that are shared across
// applications. A typical path is C:\Program Files\Common.
// Valid only for Windows NT, Windows 2000, and Windows XP systems.
// Not valid for Windows Millennium Edition (Windows Me).
CommonProgramFiles = 0x002b,
// Version 5.0. The Windows System folder. A typical
// path is C:\Windows\System32.
System = 0x0025,
// Version 5.0. The Windows directory or SYSROOT.
// This corresponds to the %windir% or %SYSTEMROOT% environment
// variables. A typical path is C:\Windows.
Windows = 0x0024,
// Fonts directory. A typical path is c:\Windows\Fonts.
Fonts = 0x0014
}
User-Defined Types:
Private Const CSIDL_WINDOWS As Integer = &H24
Sample Code:
Dim winPath As New StringBuilder(300)
If SHGetFolderPath(Nothing, CSIDL_WINDOWS, Nothing, 0, winPath) <> 0 Then
Throw New ApplicationException("Can't get window's directory")
End If
Console.WriteLine(winPath.ToString)
Sample Code C#:
StringBuilder SB = new StringBuilder();
SHGetFolderPath(IntPtr.Zero,0x0019,IntPtr.Zero,0x0000,SB);
DesktopPath = SB.ToString();
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).