public DataSourceShell(ShellAPI.IShellItem psiDirectory) { if (haveRootShell == false) { throw new Exception("The root shell item must be created before creating a sub-item"); } ShellAPI.SFGAO sfgAttribs; if (psiDirectory.GetAttributes(ShellAPI.SFGAO.SFGAO_FILESYSTEM, out sfgAttribs) == 0) { string pszSelection; IntPtr pszDisplay = IntPtr.Zero; if (psiDirectory.GetDisplayName(ShellAPI.SIGDN.SIGDN_NORMALDISPLAY, out pszDisplay) == 0) { if (pszDisplay != IntPtr.Zero) { pszSelection = Marshal.PtrToStringAuto(pszDisplay); DisplayName = pszSelection; } } isFolder = true; // for display it as a folder. hasSubFolder = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_HASSUBFOLDER); IsBrowsable = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_BROWSABLE); IsStream = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_STREAM); IsLink = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_LINK); isFileSystem = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_FILESYSTEM); IsHidden = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_HIDDEN); IsRemovable = Convert.ToBoolean(sfgAttribs & ShellAPI.SFGAO.SFGAO_REMOVABLE); LoadFileInfo(DisplayName, 0); try { //Int32 result = ShellAPI.ItemBindToHandler(psiDirectory, out shellFolder); //if (result != 0) // Marshal.ThrowExceptionForHR((int)result); IntPtr pIDL = IntPtr.Zero; if (ShellAPI.ILCreateFromPath(psiDirectory, out pIDL) == 0) { ptrIDL = pIDL; shellItemPath = GetPath(); LoadFileInfo(ptrIDL); } } catch (Exception ex) { LogHelper.Debug("ShellAPI.ILCreateFromPath Failed", ex); } } }