private static String[] ShowDialogInner(IFileOpenDialog dialog, IntPtr parentWindowHandle, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex, FileOpenOptions flags) { flags = flags | FileOpenOptions.NoTestFileCreate | FileOpenOptions.PathMustExist | FileOpenOptions.ForceFilesystem; dialog.SetOptions(flags); if (title != null) { dialog.SetTitle(title); } if (initialDirectory != null) { IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory); if (initialDirectoryShellItem != null) { dialog.SetFolder(initialDirectoryShellItem); } } if (defaultFileName != null) { dialog.SetFileName(defaultFileName); } Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex); HResult result = dialog.Show(parentWindowHandle); if (result == HResult.Ok) { IShellItemArray resultsArray; dialog.GetResults(out resultsArray); String[] fileNames = Utility.GetFileNames(resultsArray); return(fileNames); } else if (result == HResult_Win32_Canceled) { // Cancelled by user. return(null); } else { UInt32 win32ErrorCode = Utility.Win32ErrorFromHResult((UInt32)result); throw new Win32Exception(error: (Int32)win32ErrorCode); } }
private static String[] ShowDialogInner(IFileOpenDialog dialog, IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex, FileOpenOptions flags) { flags = flags | FileOpenOptions.NoTestFileCreate | FileOpenOptions.PathMustExist | FileOpenOptions.ForceFilesystem; dialog.SetOptions(flags); if (title != null) { dialog.SetTitle(title); } if (initialDirectory != null) { IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory); if (initialDirectoryShellItem != null) { dialog.SetFolder(initialDirectoryShellItem); } } if (defaultFileName != null) { dialog.SetFileName(defaultFileName); } Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex); HResult result = dialog.Show(parentHWnd); HResult cancelledAsHResult = Utility.HResultFromWin32((int)HResult.Win32ErrorCanceled); if (result == cancelledAsHResult) { // Cancelled return(null); } else { // OK IShellItemArray resultsArray; dialog.GetResults(out resultsArray); String[] fileNames = Utility.GetFileNames(resultsArray); return(fileNames); } }
private static String ShowDialogInner(IFileOpenDialog dialog, IntPtr parentWindowHandle, String title, String initialDirectory) { //IFileDialog ifd = dialog; FileOpenOptions flags = FileOpenOptions.NoTestFileCreate | FileOpenOptions.PathMustExist | FileOpenOptions.PickFolders | FileOpenOptions.ForceFilesystem; dialog.SetOptions(flags); if (title != null) { dialog.SetTitle(title); } if (initialDirectory != null) { IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory); if (initialDirectoryShellItem != null) { dialog.SetFolder(initialDirectoryShellItem); } } HResult result = dialog.Show(parentWindowHandle); if (result == HResult.Ok) { IShellItemArray resultsArray; dialog.GetResults(out resultsArray); String[] fileNames = Utility.GetFileNames(resultsArray); return(fileNames.Length == 0 ? null : fileNames[0]); } else if (result == HResult_Win32_Canceled) { // Cancelled by user. return(null); } else { UInt32 win32ErrorCode = Utility.Win32ErrorFromHResult((UInt32)result); throw new Win32Exception(error: (Int32)win32ErrorCode); } }
private static String ShowDialogInner(IFileOpenDialog dialog, IntPtr parentHWnd, String title, String initialDirectory) { //IFileDialog ifd = dialog; FileOpenOptions flags = FileOpenOptions.NoTestFileCreate | FileOpenOptions.PathMustExist | FileOpenOptions.PickFolders | FileOpenOptions.ForceFilesystem; dialog.SetOptions(flags); if (title != null) { dialog.SetTitle(title); } if (initialDirectory != null) { IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory); if (initialDirectoryShellItem != null) { dialog.SetFolder(initialDirectoryShellItem); } } HResult result = dialog.Show(parentHWnd); HResult cancelledAsHResult = Utility.HResultFromWin32((int)HResult.Win32ErrorCanceled); if (result == cancelledAsHResult) { // Cancelled return(null); } else { // OK IShellItemArray resultsArray; dialog.GetResults(out resultsArray); String[] fileNames = Utility.GetFileNames(resultsArray); return(fileNames.Length == 0 ? null : fileNames[0]); } }
void SetDialogResults(IFileOpenDialog dialog) { IShellItem item; if (!this.Multiselect) { dialog.GetResult(out item); string path, value; GetPathAndElementName(item, out path, out value); this.SelectedPath = path; this.SelectedPaths = new[] { path }; this.SelectedElementName = value; this.SelectedElementNames = new[] { value }; } else { IShellItemArray items; dialog.GetResults(out items); uint count; items.GetCount(out count); this.SelectedPaths = new string[count]; this.SelectedElementNames = new string[count]; for (uint i = 0; i < count; ++i) { items.GetItemAt(i, out item); string path, value; GetPathAndElementName(item, out path, out value); this.SelectedPaths[i] = path; this.SelectedElementNames[i] = value; } this.SelectedPath = null; this.SelectedElementName = null; } }
internal override string[] ProcessVistaFiles(IFileDialog dialog) { IFileOpenDialog fileOpenDialog = (IFileOpenDialog)dialog; if (this.Multiselect) { IShellItemArray results = fileOpenDialog.GetResults(); uint count = results.GetCount(); string[] array = new string[count]; for (uint num = 0U; num < count; num += 1U) { IShellItem itemAt = results.GetItemAt(num); array[(int)num] = itemAt.GetDisplayName((SIGDN)2147647488U); } return(array); } IShellItem result = fileOpenDialog.GetResult(); return(new string[] { result.GetDisplayName((SIGDN)2147647488U) }); }