Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
SHGetNameFromIDList (shell32)

The format is determined by then SIGDN Enum

C# Signature:

[DllImport("shell32.dll", SetLastError=true)]
static extern TODO SHGetNameFromIDList(TODO);

<System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHGetNameFromIDList")> _

Private Shared Function SHGetNameFromIDList( _

   <System.Runtime.InteropServices.InAttribute()> _
   ByVal pidl As System.IntPtr, _
   ByVal sigdnName As SIGDN, _
   ByRef ppszName As System.IntPtr) As Integer

End Function

Alternative Managed API:

Do you know more? Please contribute it!

string userApplicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);



Tips & Tricks:

Please add some!

' Sample in VB.NET

Imports System

Imports System.Runtime.InteropServices

Public Enum CSIDL

    APPDATA = &H1A
    CONTROLS = &H3
    COOKIES = &H21
    DESKTOP = &H0
    DRIVES = &H11
    FLAG_CREATE = &H8000
    FLAG_MASK = &HFF00
    FLAG_NO_ALIAS = &H1000
    FONTS = &H14
    HISTORY = &H22
    INTERNET = &H1
    NETHOOD = &H13
    NETWORK = &H12
    PERSONAL = &H5
    PRINTERS = &H4
    PROFILE = &H28
    PROGRAMS = &H2
    RECENT = &H8
    RESOURCES = &H38
    SENDTO = &H9
    STARTUP = &H7
    SYSTEM = &H25
    SYSTEMX86 = &H29
    TEMPLATES = &H15
    WINDOWS = &H24

End Enum


Public Enum SFGAO As UInteger

    CANCOPY = &H1                 '   Objects can be copied    (DROPEFFECT_COPY)
    CANMOVE = &H2                 '   Objects can be moved     (DROPEFFECT_MOVE)
    CANLINK = &H4                 '   Objects can be linked    (DROPEFFECT_LINK)
    STORAGE = &H8          '   supports BindToObject(IID_IStorage)
    CANRENAME = &H10         '   Objects can be renamed
    CANDELETE = &H20         '   Objects can be deleted
    HASPROPSHEET = &H40            '   Objects have property sheets
    DROPTARGET = &H100           '   Objects are drop target
     SYSTEM= &H1000  ' Windows 7 and later. The specified items are system items.
    ENCRYPTED = &H2000           '   object is encrypted (use alt color)
    ISSLOW = &H4000            '   'slow' object
    GHOSTED = &H8000         '   ghosted icon
    LINK = &H10000           '   Shortcut (link)
    SHARE = &H20000            '   shared
    [READONLY] = &H40000         '   read-only
    HIDDEN = &H80000         '   hidden object
    FILESYSANCESTOR = &H10000000         '   may contain children with FILESYSTEM
    FOLDER = &H20000000            '   support BindToObject(IID_IShellFolder)
    FILESYSTEM = &H40000000            '   is a win32 file system object (file/folder/root)
    HASSUBFOLDER = &H80000000UI          '   may contain children with FOLDER
    CONTENTSMASK = &H80000000UI
    VALIDATE = &H1000000         '   invalidate cached information
    REMOVABLE = &H2000000          '   is this removeable media?
    COMPRESSED = &H4000000           '   Object is compressed (use alt color)
    BROWSABLE = &H8000000          '   supports IShellFolder, but only implements CreateViewObject() (non-folder view)
    NONENUMERATED = &H100000         '   is a non-enumerated object
    NEWCONTENT = &H200000          '   should show bold in explorer tree
    CANMONIKER = &H400000          '   defunct
    HASSTORAGE = &H400000          '   defunct
    STREAM = &H400000          '   supports BindToObject(IID_IStream)
    STORAGEANCESTOR = &H800000           '   may contain children with STORAGE or STREAM
    STORAGECAPMASK = &H70C50008            '   for determining storage capabilities, ie for open/save semantics

End Enum

<Flags()> _

Public Enum SHGFI

    ICON = &H100
    TYPENAME = &H400
    ATTRIBUTES = &H800
    EXETYPE = &H2000
    LINKOVERLAY = &H8000
    SELECTED = &H10000
    ATTR_SPECIFIED = &H20000
    OPENICON = &H2
    PIDL = &H8

End Enum

Public Enum SIGDN As UInteger

    FILESYSPATH = &H80058000UI
    URL = &H80068000UI

End Enum

Public Class SHGetNameFromIDList#_TEST

#Region "Native Methods"

    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="ILFree")> _
    Private Shared Sub ILFree(<System.Runtime.InteropServices.InAttribute()> ByVal pidl As System.IntPtr)
    End Sub

    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHGetNameFromIDList")> _
    Private Shared Function SHGetNameFromIDList( _
   <System.Runtime.InteropServices.InAttribute()> _
   ByVal pidl As System.IntPtr, _
   ByVal sigdnName As SIGDN, _
   ByRef ppszName As System.IntPtr) As Integer
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHParseDisplayName")> _
    Private Shared Function SHParseDisplayName( _

<System.Runtime.InteropServices.InAttribute(), _

System.Runtime.InteropServices.MarshalAsAttribute( _

System.Runtime.InteropServices.UnmanagedType.LPWStr)> _

ByVal pszName As String, <System.Runtime.InteropServices.InAttribute()> _

ByVal pbc As System.IntPtr, _

ByRef ppidl As System.IntPtr, _

ByVal sfgaoIn As SFGAO, _

ByRef psfgaoOut As SFGAO) As Integer

    End Function

    Private Shared Function SHGetFolderLocation(hwndOwner As IntPtr, nFolder As Integer,
   hToken As IntPtr, dwReserved As UInteger, ByRef ppidl As IntPtr) As Integer
    End Function

#End Region

    Public Shared Function GetNameFromPIDL(pidl As IntPtr, _
       displayType As SIGDN) As String
        Dim ptr As IntPtr = Marshal.AllocHGlobal(300)
        SHGetNameFromIDList(pidl, displayType, ptr)
        Dim path As String = Marshal.PtrToStringAuto(ptr)
        Return path
    End Function

    Private Function PIDLFromCSIDL(csidlInt As Integer) As IntPtr
        If Not [Enum].IsDefined(GetType(CSIDL), csidlInt) Then Return IntPtr.Zero
        Dim ptr As IntPtr = IntPtr.Zero
        SHGetFolderLocation(IntPtr.Zero, CInt(csidlInt), IntPtr.Zero, 0, ptr)
        Return ptr
    End Function

    Private Function PIDLFromParseName(parseName As String) As IntPtr
        Dim ptr As IntPtr = IntPtr.Zero
        SHParseDisplayName(parseName, IntPtr.Zero, ptr, 0, 0)
        Return ptr
    End Function

    'Example = Get ParseName for Control Panel
    Public Function ControlPanelParseName() As String
        Dim CplCsidl As CSIDL = CSIDL.CONTROLS
        Dim ptrLoc As IntPtr = IntPtr.Zero
        SHGetFolderLocation(IntPtr.Zero, CInt(CplCsidl), IntPtr.Zero, 0, ptrLoc)
        Dim parseName As String = GetNameFromPIDL(ptrLoc, SIGDN.DESKTOPABSOLUTEPARSING)
        Return parseName
    End Function

    'Example = Get Display Name for 'My Computer'
    Public Function ComputerDisplayName() As String
        Dim pcCsidl As CSIDL = CSIDL.DRIVES
        Dim ptrLoc As IntPtr = IntPtr.Zero
        SHGetFolderLocation(IntPtr.Zero, CInt(pcCsidl), IntPtr.Zero, 0, ptrLoc)
        Dim displayName As String = GetNameFromPIDL(ptrLoc, SIGDN.NORMALDISPLAY)
        Return displayName
    End Function

End Class

' ( ) Jens Madsen, 5/2012


Please edit this page!

Do you have...

  • 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).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version