Exemple #1
0
        public DialogResult ShowDialog()
        {
            int result = _dialog.Show(GetActiveWindow());

            if (result < 0)
            {
                if ((uint)result == (uint)HRESULT.E_CANCELLED)
                {
                    return(DialogResult.Cancel);
                }
                throw Marshal.GetExceptionForHR(result);
            }

            IShellItem dialogResult;

            _dialog.GetResult(out dialogResult);
            dialogResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out _fileName);

            IFileDialogCustomize customize = (IFileDialogCustomize)_dialog;

            customize.GetCheckButtonState(RunManualCheckboxId, out _runManualMode);
            model.PreferenceSettings.OpenFileInManualExecutionMode = _runManualMode;

            return(DialogResult.OK);
        }
Exemple #2
0
        public static string Show(IWin32Window parent)
        {
            IFileDialog dialog = null;

            try
            {
                dialog = new NativeFileOpenDialog();
                dialog.SetOptions(FOS.FOS_PICKFOLDERS);
                if (dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0)
                {
                    string     result = string.Empty;
                    IShellItem item;
                    dialog.GetResult(out item);
                    return(GetFilePathFromShellItem(item));
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (dialog != null)
                {
                    Marshal.FinalReleaseComObject(dialog);
                }
            }
        }
Exemple #3
0
        private void GetNativeDialogResult(NativeFileOpenDialog nativeFileOpenDialog)
        {
            IShellItem item;

            nativeFileOpenDialog.GetResult(out item);
            item.GetDisplayName(CommonDialogNativeMethods.SIGDN.SIGDN_FILESYSPATH, out m_FolderPath);
        }
Exemple #4
0
        public DialogResult ShowDialog()
        {
            NativeFileOpenDialog dialog = null;

            try
            {
                // If the caller did not specify a starting path, or set it to null,
                // it is not healthy as it causes SHCreateItemFromParsingName to
                // throw E_INVALIDARG (0x80070057). Setting it to an empty string.
                //
                if (SelectedPath == null)
                {
                    SelectedPath = string.Empty;
                }

                dialog = new NativeFileOpenDialog();

                dialog.SetTitle(Title);

                object shellItem;
                // IShellItem GUID
                Guid guid    = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
                int  hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem);
                if ((uint)hresult != (uint)HRESULT.S_OK)
                {
                    throw Marshal.GetExceptionForHR(hresult);
                }
                dialog.SetFolder((IShellItem)shellItem);

                dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST);

                IntPtr hWnd = new WindowInteropHelper(Owner).Handle;
                hresult = dialog.Show(hWnd);
                if (hresult < 0)
                {
                    if ((uint)hresult == (uint)HRESULT.E_CANCELLED)
                    {
                        return(DialogResult.Cancel);
                    }
                    throw Marshal.GetExceptionForHR(hresult);
                }

                string     path;
                IShellItem item;
                dialog.GetResult(out item);
                item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
                SelectedPath = path;

                return(DialogResult.OK);
            }
            finally
            {
                if (dialog != null)
                {
                    Marshal.FinalReleaseComObject(dialog);
                }
            }
        }
        public DialogResult ShowDialog()
        {
            NativeFileOpenDialog dialog = null;

            try
            {
                // If the caller did not specify a starting path, or set it to null,
                // it is not healthy as it causes SHCreateItemFromParsingName to 
                // throw E_INVALIDARG (0x80070057). Setting it to an empty string.
                // 
                if (SelectedPath == null)
                    SelectedPath = string.Empty;

                dialog = new NativeFileOpenDialog();

                dialog.SetTitle(Title);

                object shellItem;
                // IShellItem GUID
                Guid guid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
                int hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem);
                if ((uint)hresult != (uint)HRESULT.S_OK)
                    throw Marshal.GetExceptionForHR(hresult);
                dialog.SetFolder((IShellItem)shellItem);

                dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST);

                IntPtr hWnd = new WindowInteropHelper(Owner).Handle;
                hresult = dialog.Show(hWnd);
                if (hresult < 0)
                {
                    if ((uint)hresult == (uint)HRESULT.E_CANCELLED)
                        return DialogResult.Cancel;
                    throw Marshal.GetExceptionForHR(hresult);
                }

                string path;
                IShellItem item;
                dialog.GetResult(out item);
                item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
                SelectedPath = path;

                return DialogResult.OK;
            }
            finally 
            {
                if (dialog != null)
                    Marshal.FinalReleaseComObject(dialog);
            }
        }
Exemple #6
0
		public static string Show(IWin32Window parent)
		{
			IFileDialog dialog = null;
			try
			{
				dialog = new NativeFileOpenDialog();
				dialog.SetOptions(FOS.FOS_PICKFOLDERS);
				if(dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0)
				{
					string result = string.Empty;
					IShellItem item;
					dialog.GetResult(out item);
					return GetFilePathFromShellItem(item);
				}
				else
				{
					return null;
				}
			}
			finally
			{
				if(dialog != null)
				{
					Marshal.FinalReleaseComObject(dialog);
				}
			}
		}