Пример #1
0
        public static IShellItem2 GetShellItemForPath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                // Internal function.  Should have verified this before calling if we cared.
                return(null);
            }

            Guid    iidShellItem2 = new Guid(IID.ShellItem2);
            object  unk;
            HRESULT hr = NativeMethodsShell.SHCreateItemFromParsingName(path, null, ref iidShellItem2, out unk);

            // Silently absorb errors such as ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND.
            // Let others pass through
            if (hr == (HRESULT)Win32Error.ERROR_FILE_NOT_FOUND || hr == (HRESULT)Win32Error.ERROR_PATH_NOT_FOUND)
            {
                hr  = HRESULT.S_OK;
                unk = null;
            }

            hr.ThrowIfFailed();

            return((IShellItem2)unk);
        }