Пример #1
0
        public string SelectFolder(string caption, string initialPath, IntPtr parentHandle)
        {
            _initialPath = initialPath;
            StringBuilder sb = new StringBuilder(256);
            IntPtr pidl = IntPtr.Zero;
            BROWSEINFO bi = new BROWSEINFO();
            bi.hwndOwner = parentHandle;
            bi.pidlRoot = IntPtr.Zero;
            bi.pszDisplayName = initialPath;
            bi.lpszTitle = caption;
            bi.ulFlags = NativeMethods.BIF_NEWDIALOGSTYLE | NativeMethods.BIF_SHAREABLE;
            bi.lpfn = new BrowseCallBackProc(OnBrowseEvent);
            bi.lParam = IntPtr.Zero;
            bi.iImage = 0;

            try {
                pidl = NativeMethods.SHBrowseForFolder(ref bi);
                if (0 == NativeMethods.SHGetPathFromIDList(pidl, sb)) {
                    return null;
                }
            }
            finally {
                // Caller is responsible for freeing this memory.
                Marshal.FreeCoTaskMem(pidl);
            }

            return sb.ToString();
        }
Пример #2
0
        public string SelectFolder(string caption, string initialPath, IntPtr parentHandle)
        {
            _initialPath = initialPath;
            StringBuilder sb   = new StringBuilder(256);
            IntPtr        pidl = IntPtr.Zero;
            BROWSEINFO    bi   = new BROWSEINFO();

            bi.hwndOwner      = parentHandle;
            bi.pidlRoot       = IntPtr.Zero;
            bi.pszDisplayName = initialPath;
            bi.lpszTitle      = caption;
            bi.ulFlags        = NativeMethods.BIF_NEWDIALOGSTYLE | NativeMethods.BIF_SHAREABLE;
            bi.lpfn           = new BrowseCallBackProc(OnBrowseEvent);
            bi.lParam         = IntPtr.Zero;
            bi.iImage         = 0;

            try {
                pidl = NativeMethods.SHBrowseForFolder(ref bi);
                if (0 == NativeMethods.SHGetPathFromIDList(pidl, sb))
                {
                    return(null);
                }
            }
            finally {
                // Caller is responsible for freeing this memory.
                Marshal.FreeCoTaskMem(pidl);
            }

            return(sb.ToString());
        }
Пример #3
0
 public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);
Пример #4
0
 public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);