public static void GetInput(NativeOSWindow parent, Browser browser, bool modal, SendResult <BrowseType> sendResult, Action <String, Action <String> > importCallback, String prompt, String wildcard, String extension) { BrowserWindow <BrowseType> inputBox = createInputBox(browser, modal, sendResult); inputBox.importButton.MouseButtonClick += (source, e) => { FileOpenDialog openDialog = new FileOpenDialog(parent, prompt, wildcard: wildcard); openDialog.showModal((result, paths) => { if (result == NativeDialogResult.OK) { String path = paths.First(); String ext = Path.GetExtension(path); if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase)) { importCallback(path, previewPath => { ThreadManager.invoke(new Action(() => { BrowserNode node = new BrowserNode(Path.GetFileName(previewPath), previewPath); inputBox.browserTree.Nodes.First().Children.add(inputBox.addNodes(node, node)); inputBox.browserTree.layout(); })); }); } else { MessageBox.show(String.Format("Cannot open a file with extension '{0}'.", extension), "Can't Load File", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok); } } }); }; }
private void btnLoad_Click(object sender, EventArgs e) { DialogResult result = FileOpenDialog.ShowDialog(); if (result == DialogResult.OK) { string file = FileOpenDialog.FileName; string[] CDs = File.ReadAllLines(file); listCD = new List <CDInformation>(); if (CDs == null || CDs.Count() == 0) { MessageBox.Show("File is empty!!!", "Empty File", MessageBoxButtons.OK); return; } foreach (string CD in CDs) { string[] CDInfo = CD.Split('~'); CDInformation info = new CDInformation( CDInfo[0], CDInfo[1], CDInfo[2], CDInfo[3], int.Parse(CDInfo[4])); string[] songs = CDInfo[5].Split('#'); foreach (string song in songs) { info.Song.Add(song); } listCD.Add(info); } loadListData(); } }
public void OpenFile() { FileOpenDialog dialog = new FileOpenDialog(); dialog.structSize = Marshal.SizeOf(dialog); dialog.filter = "exe files\0*.exe\0All Files\0*.*\0\0"; dialog.file = new string(new char[256]); dialog.maxFile = dialog.file.Length; dialog.fileTitle = new string(new char[64]); dialog.maxFileTitle = dialog.fileTitle.Length; dialog.initialDir = UnityEngine.Application.dataPath; //默认路径 dialog.title = "Open File Dialog"; dialog.defExt = "exe"; //显示文件的类型 //注意一下项目不一定要全选 但是0x00000008项不要缺少 dialog.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DialogShow.GetOpenFileName(dialog)) { Debug.Log(dialog.file); } }
void OnChooseFolderDialog(object sender, RoutedEventArgs e) { var dlg = new FileOpenDialog { Multiselect = true, FolderPicker = true, CheckPathExists = true, }; var target = e.Source as FrameworkElement; string directory = target.Tag as string; if (!string.IsNullOrEmpty(directory)) { // Get first path in the list directory = directory.Split(',')[0].TrimEnd(Path.PathSeparator); // Make relative paths absolute (relative to the config file) directory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(configFilePath), directory)); dlg.InitialDirectory = directory; } if (dlg.ShowDialog(this) == true) { target.Tag = string.Join(",", dlg.FileNames); } }
public void showOpenFileDialog(string filterString, SendResult <string> resultCallback) { FileOpenDialog dlg = new FileOpenDialog(wildcard: filterString, selectMultiple: false); dlg.showModal((mResult, mFiles) => { fileOpenResults(mResult, mFiles, resultCallback, dlg); }); }
private string ChooseFile(string format) { FileOpenDialog openFileDialog = new FileOpenDialog(format); openFileDialog.Show(); ModelPath userPath = openFileDialog.GetSelectedModelPath(); ModelPathUtils.ConvertModelPathToUserVisiblePath(userPath); return(ModelPathUtils.ConvertModelPathToUserVisiblePath(userPath)); }
public string BrowseBoot(Window owner, PresetModel preset, BootType type) { using (var dialog = new FileOpenDialog()) { const string BiosFileName = "etfsboot.com"; const string UefiFileName = "efisys.bin"; string bootFolderPath; string bootFileName; string bootFileExtension; string extension; string clientGuid; string title; string fileName; if (type == BootType.Bios) { GetFilePathInfo(preset.BiosBoot, out bootFolderPath, out bootFileName, out bootFileExtension); extension = Path.GetExtension(BiosFileName); clientGuid = "E8BEE349-1A4A-4E04-B8B9-B15FF1EF9125"; title = "BIOS"; fileName = bootFileName ?? BiosFileName; } else if (type == BootType.Uefi) { GetFilePathInfo(preset.UefiBoot, out bootFolderPath, out bootFileName, out bootFileExtension); extension = Path.GetExtension(UefiFileName); clientGuid = "A6A65946-6FCD-4DCA-AEB1-85ABF5FE3CAE"; title = "UEFI"; fileName = bootFileName ?? UefiFileName; } else { throw new InvalidOperationException("The specified boot type is not implemented."); } dialog.SetClientGuid(new Guid(clientGuid)); dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); dialog.SetTitle($"{title} boot sector file"); dialog.SetFileTypes($"Boot files (*{extension})|*{extension}|All files (*.*)|*.*"); dialog.SetFileName(fileName); dialog.SetFileTypeIndex(bootFileExtension == null || bootFileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) ? 1 : 2); dialog.SetOkButtonLabel("Select"); dialog.SetCancelButtonLabel("Cancel"); dialog.SetFileNameLabel("Boot sector file :"); dialog.DontAddToRecent = true; if (PathHelper.DirectoryExists(bootFolderPath)) { dialog.SetFolder(bootFolderPath); } return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null); } }
public void SetPath() { this.Dispatcher.BeginInvoke(new Action(() => { string path = FileOpenDialog.ShowDialog(); if (path != string.Empty) { AppPropertys.appSetting.DownloadFolder = path + "\\"; defaultFolder.Text = AppPropertys.appSetting.DownloadFolder; } })); }
void browseDestination_MouseButtonClick(Widget source, EventArgs e) { FileOpenDialog open = new FileOpenDialog(parentWindow, wildcard: Filter, selectMultiple: false); open.showModal((result, path) => { if (result == NativeDialogResult.OK) { destTextBox.OnlyText = path.FirstOrDefault(); } }); }
void showOpenProjectDialog() { editorController.stopPlayingTimelines(); FileOpenDialog fileDialog = new FileOpenDialog(MainWindow.Instance, "Open a project.", "", "", "", false); fileDialog.showModal((result, paths) => { if (result == NativeDialogResult.OK) { String path = paths.First(); editorController.openProject(Path.GetDirectoryName(path)); } }); }
/// <summary>Shows the open translation dialog and possibly opens a file.</summary> /// <remarks>If there's a translation currently open with unsaved changes, a warning dialog /// is shown before opening the new file.</remarks> public void TranslationOpen() { FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileTranslationOpenDialog)) as FileOpenDialog; dialog.Show(); bool toOpen = dialog.WaitForResponse(); if (toOpen && ToOpenTranslationAfterWarning()) { string filename = dialog.Filename; int codePage = (dialog.Encoding.Equals(EncodingDescription.Empty) ? -1 : dialog.Encoding.CodePage); OpenTranslation(filename, codePage); } }
/// <summary> /// Show the open file dialog and return the chosen file. /// <param name="fileChosenCb">A function that is called when a file is chosen with the name of the chosen file.</param> /// </summary> public void openFile(FileChosen fileChosenCb) { FileOpenDialog fileOpen = new FileOpenDialog(ParentWindow, "", DefaultDirectory, "", Filter, false); fileOpen.showModal((result, files) => { String file = files.FirstOrDefault(); if (result == NativeDialogResult.OK && !String.IsNullOrEmpty(file)) { currentFile = file; fileChosenCb(currentFile); } }); }
void browseButton_MouseButtonClick(Widget source, EventArgs e) { FileOpenDialog openDialog = new FileOpenDialog(MainWindow.Instance, "Choose an image", wildcard: "Images|*.jpg;*.jpeg;*.png"); openDialog.showModal((result, paths) => { if (result == NativeDialogResult.OK) { if (imageAtlas.containsImage(Key)) { imagePreview.setItemResource(null); imageAtlas.removeImage(Key); } String path = paths.First(); String extension = Path.GetExtension(path); if (extension.Equals(".png", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase)) { imageName = Guid.NewGuid().ToString("D") + extension; String filename = Path.Combine(subdirectory, imageName); System.Threading.ThreadPool.QueueUserWorkItem((stateInfo) => { try { using (Stream writeStream = resourceProvider.openWriteStream(filename)) { using (Stream readStream = File.Open(path, FileMode.Open, FileAccess.Read)) { readStream.CopyTo(writeStream); } } openImageBGThread(filename, true); } catch (Exception ex) { ThreadManager.invoke(() => { MessageBox.show(String.Format("Error copying file {0} to your project.\nReason: {1}", path, ex.Message), "Image Copy Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok); }); } }); } else { MessageBox.show(String.Format("Cannot open a file with extension '{0}'. Please choose a file that is a Png Image (.png) or a Jpeg (.jpg or .jpeg).", extension), "Can't Load Image", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok); } } }); }
/// <summary>Shows the open dialog and possibly opens a subtitle.</summary> /// <remarks>If there's a document currently open with unsaved changes, a warning dialog /// is shown before opening the new file.</remarks> public void Open() { FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileOpenDialog)) as FileOpenDialog; dialog.Show(); bool gotOpenResponse = dialog.WaitForResponse(); if (gotOpenResponse && ToOpenAfterWarning()) { string filename = dialog.Filename; int codePage = (dialog.Encoding.Equals(EncodingDescription.Empty) ? -1 : dialog.Encoding.CodePage); Uri videoUri = dialog.VideoUri; Open(filename, codePage, videoUri); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { Document document = commandData.get_Application().get_ActiveUIDocument().get_Document(); FileOpenDialog fileOpenDialog = new FileOpenDialog("SAT file (*.sat)|*.sat"); ((FileDialog)fileOpenDialog).set_Title("Select SAT file to import"); ((FileDialog)fileOpenDialog).Show(); ModelPath selectedModelPath = ((FileDialog)fileOpenDialog).GetSelectedModelPath(); ((FileDialog)fileOpenDialog).Dispose(); string userVisiblePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(selectedModelPath); SATImportOptions satImportOptions = new SATImportOptions(); View element = new FilteredElementCollector(document).OfClass(typeof(View)).ToElements()[0] as View; try { using (Transaction transaction = new Transaction(document, "Import SAT")) { transaction.Start(); ElementId elementId = document.Import(userVisiblePath, satImportOptions, element); using (IEnumerator <GeometryObject> enumerator1 = document.GetElement(elementId).get_Geometry(new Options()).GetEnumerator()) { while (((IEnumerator)enumerator1).MoveNext()) { using (IEnumerator <GeometryObject> enumerator2 = (enumerator1.Current as GeometryInstance).get_SymbolGeometry().GetEnumerator()) { while (((IEnumerator)enumerator2).MoveNext()) { Solid current = enumerator2.Current as Solid; FreeFormElement.Create(document, current); } } } } document.Delete(elementId); transaction.Commit(); } return((Result)0); } catch { TaskDialog.Show("Error Importing", "Something went wrong"); return((Result) - 1); } }
public static string OpenResourceFile(string filter) { FileOpenDialog dialog = new FileOpenDialog(); dialog.structSize = Marshal.SizeOf(typeof(FileOpenDialog)); dialog.filter = filter; dialog.file = new string(new char[2000]); dialog.maxFile = dialog.file.Length; dialog.initialDir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); dialog.flags = 0x00000008; GetOpenFileName(dialog); var chars = dialog.file.ToCharArray(); return(new string(chars, 0, Array.IndexOf(chars, '\0'))); }
private void OnSelectDocDefinitionFilePathnameRequested(object sender, EventArgs e) { var pathnameSelector = new FileOpenDialog(); pathnameSelector.Title = "Specify the pathname of the file containing the document-definition."; // pathnameSelector.InitialDirectory = _viewModel.DocDefinitionFilePathname; if (StringLib.HasNothing(_viewModel.DocDefinitionFilePathname)) { // pathnameSelector.SelectedFilename = "CodeMetricsComparisonReport.txt"; } var r = pathnameSelector.ShowDialog(); if (r == DisplayUxResult.Ok) { _viewModel.DocDefinitionFilePathname = pathnameSelector.SelectedFilename; } }
public static void GetInput(Browser browser, bool modal, SendResult <BrowseType> sendResult, ResourceProvider resourceProvider, Action <String, Action <String> > importCallback = null) { ImageBrowserWindow <BrowseType> inputBox = new ImageBrowserWindow <BrowseType>(browser.Prompt, resourceProvider); inputBox.setBrowser(browser); if (importCallback != null) { inputBox.importButton.MouseButtonClick += (source, e) => { FileOpenDialog openDialog = new FileOpenDialog(MainWindow.Instance, "Choose Image", "Images|*.jpg;*.jpeg;*.png"); openDialog.showModal((result, paths) => { if (result == NativeDialogResult.OK) { String path = paths.First(); String extension = Path.GetExtension(path); if (extension.Equals(".png", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase) || extension.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase)) { importCallback(path, previewPath => { ThreadManager.invoke(new Action(() => { BrowserNode node = new BrowserNode("", previewPath); inputBox.addNodes(node, node); })); }); } else { MessageBox.show(String.Format("Cannot open a file with extension '{0}'. Please choose a file that is a Png Image (.png) or a Jpeg (.jpg or .jpeg).", extension), "Can't Load Image", MessageBoxStyle.IconWarning | MessageBoxStyle.Ok); } } }); }; } else { inputBox.importButton.Visible = false; } inputBox.SendResult = sendResult; inputBox.Closing += new EventHandler <DialogCancelEventArgs>(inputBox_Closing); inputBox.Closed += new EventHandler(inputBox_Closed); inputBox.center(); inputBox.open(modal); }
private bool ShowDialog(IntPtr owner) { IFileOpenDialog fod = null; try { fod = new FileOpenDialog() as IFileOpenDialog; fod.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM); if (!string.IsNullOrEmpty(InitialPath)) { uint attribute = 0U; if ((SHILCreateFromPath(InitialPath, out IntPtr idl, ref attribute) == S_OK) && (SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out IShellItem item) == S_OK)) { fod.SetFolder(item); } } if (!string.IsNullOrEmpty(Title)) { fod.SetTitle(Title); } if (fod.Show(owner) != S_OK) { return(false); } SelectedPath = fod.GetResult().GetDisplayName(SIGDN.SIGDN_FILESYSPATH); return(true); } catch (COMException ce) { Debug.WriteLine($"Failed to manage open folder dialog.\r\n{ce}"); return(false); } finally { if (fod is not null) { Marshal.FinalReleaseComObject(fod); } } }
void OnChooseFolderDialog(object sender, RoutedEventArgs e) { var target = e.Source as FrameworkElement; string origFirstValue = (target.Tag as string ?? string.Empty).Split(',')[0].TrimEnd(Path.PathSeparator); var dlg = new FileOpenDialog { Multiselect = true, FolderPicker = true, CheckPathExists = true, InitialDirectory = origFirstValue }; if (dlg.ShowDialog(this) == true) { target.Tag = string.Join(",", dlg.FileNames); } }
private LinkedList <string> processingOpenFileCommand() { JSONParser jsonParser = new JSONParser(); LinkedList <string> sites = new LinkedList <string>(); crawlerHandler.ConsoleOutput = "Processing...\n"; string json = FileOpenDialog.ShowDialog(); if (json != "Canceled") { sites = jsonParser.parse(json); } else { crawlerHandler.ConsoleOutput = "Canceled.\n\n"; } return(sites); }
void OnChoosePresetDialog(object sender, RoutedEventArgs e) { string origFirstValue = (Preset.Text ?? string.Empty).Split(',')[0]; var dlg = new FileOpenDialog { CheckPathExists = true, CheckFileExists = false, Filter = "Preset Files (*.ini, *.txt)|*.ini;*.txt", FileName = origFirstValue, DefaultExt = ".ini", InitialDirectory = Path.GetDirectoryName(origFirstValue), }; if (dlg.ShowDialog(this) == true) { Preset.Text = dlg.FileName; } }
void showOpenProjectDialog() { try { slideEditController.stopPlayingTimelines(); FileOpenDialog fileDialog = new FileOpenDialog(MainWindow.Instance, "Open a project.", "", "", openWildcard, false); fileDialog.showModal((result, paths) => { if (result == NativeDialogResult.OK) { String path = paths.First(); slideEditController.openProject(path); } }); } catch (Exception ex) { MessageBox.show(String.Format("{0} loading the project. Message {1}.", ex.GetType().Name, ex.Message), "Project Load Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok); } }
//End of Transfer Tab and start of Comparer Tab private void OpenFile(bool is2) { #if DEBUG Log.GetInstence().WriteLine("OpenFile has been called"); #endif FileOpenDialog.Multiselect = false; DialogResult result = FileOpenDialog.ShowDialog(); if (result == DialogResult.OK) { if (is2) { File2Loc.Text = FileOpenDialog.FileName; } else { File1Loc.Text = FileOpenDialog.FileName; } } }
public string BrowseFile(Window owner, string filePath) { using (var dialog = new FileOpenDialog()) { dialog.SetClientGuid(new Guid("1941C841-398F-486F-8542-A0B2250F406F")); dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); dialog.SetTitle("Location of the file to be computed"); dialog.SetOkButtonLabel("Select"); dialog.SetCancelButtonLabel("Cancel"); dialog.SetFileNameLabel("File name :"); dialog.DontAddToRecent = true; if (PathHelper.FileExists(filePath)) { dialog.SetFileName(Path.GetFileName(filePath)); dialog.SetFolder(Path.GetDirectoryName(filePath)); } return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null); } }
public string BrowseSource(Window owner, string source) { using (var dialog = new FileOpenDialog()) { dialog.SetClientGuid(new Guid("6DD0F3B6-0F48-4F5B-8690-4866D4B9EAF2")); dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); dialog.SetTitle("Source location of the files and folders to be included in the image"); dialog.SetOkButtonLabel("Select"); dialog.SetCancelButtonLabel("Cancel"); dialog.SetFileNameLabel("Source location :"); dialog.PickFolders = true; dialog.DontAddToRecent = true; if (PathHelper.DirectoryExists(source)) { dialog.SetFolder(source); } return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null); } }
public static string OpenFile(string types) { FileOpenDialog dialog = new FileOpenDialog(); dialog.structSize = Marshal.SizeOf(dialog); string[] type = types.Split('|'); dialog.filter = ""; for (int i = 0; i < type.Length; ++i) { dialog.filter += type[i] + " file\0*." + type[i]; if (i < type.Length - 1) { dialog.filter += "\0"; } } dialog.filter += "\0All Files\0*.*\0\0"; dialog.file = new string(new char[256]); dialog.maxFile = dialog.file.Length; dialog.fileTitle = new string(new char[64]); dialog.maxFileTitle = dialog.fileTitle.Length; dialog.initialDir = UnityEngine.Application.dataPath; //默认路径 dialog.title = "Open File Dialog"; dialog.defExt = type[0]; dialog.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DialogShow.GetOpenFileName(dialog)) { // Debug.Log(dialog.file); return(dialog.file); } return(""); }
/// <summary> /// カスタムファイル選択ダイアログを表示します。 /// </summary> /// <returns></returns> public ShellFile ShowCustomFileOpenDialog() { using (var dialog = new FileOpenDialog()) { // Custom Controls var button1 = new FileDialogButton("button", "Button1"); button1.Click += (_, args) => MessageBox.Show("Button1", "Message"); dialog.Controls.Add(button1); var combo1 = new FileDialogComboBox("combo1", new FileDialogComboBoxItem("Item1"), new FileDialogComboBoxItem("Item2"), new FileDialogComboBoxItem("Item3")); dialog.Controls.Add(combo1); if (dialog.Show() == FileDialogResult.Ok) { return(dialog.GetShellFiles().FirstOrDefault()); } return(null); } }
static public string Open() { #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN FileOpenDialog ofn = new FileOpenDialog(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Javascript Files\0*.js\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = Application.dataPath; ofn.title = "Select Script"; ofn.defExt = "JS"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (SelectFile(ofn)) { return(ofn.file); } #endif return(null); }
// outPath: Resource 下的路径 private static void ImportVideoFile(string outDir, string prefix) { FileOpenDialog dialog = new FileOpenDialog(); dialog.structSize = Marshal.SizeOf(dialog); dialog.filter = ".mp4\0*.mp4\0webm文件\0*.webm"; dialog.file = new string(new char[256]); dialog.maxFile = dialog.file.Length; dialog.fileTitle = new string(new char[64]); dialog.maxFileTitle = dialog.fileTitle.Length; dialog.initialDir = UnityEngine.Application.streamingAssetsPath; //默认路径 dialog.title = "Open File Dialog"; //dialog.defExt = "mp4";//显示文件的类型 //注意一下项目不一定要全选 但是0x00000008项不要缺少 dialog.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DialogShow.GetOpenFileName(dialog)) { string destDir = Application.streamingAssetsPath + "/Resources/" + outDir + "/Videos/"; string videoName = prefix + "_" + dialog.fileTitle; File.Copy(dialog.file, destDir + videoName, true); Debug.Log("复制成功:" + destDir + videoName); GameObject.Find("GetImage").GetComponent <GetImage>().GeneratePreviewImage( ResAPI.Instance.FillVideoPath(videoName), Application.streamingAssetsPath + "/Resources/" + outDir + "/Thumbnails/" ); } }
public SelectFileDialog() { fod = new FileOpenDialog(); ifod = (IFileOpenDialog)fod; }
public SelectFolderDialog() { fod = new FileOpenDialog(); ifod = (IFileOpenDialog)fod; FOS fos; ifod.GetOptions(out fos); ifod.SetOptions(fos | FOS.FOS_PICKFOLDERS); // Fix an apparent bug where the default folder is inside the last selected folder rather than selecting it in parent folder IShellItem defaultFolder; ifod.GetFolder(out defaultFolder); if (defaultFolder != null) { IShellItem parentFolder; defaultFolder.GetParent(out parentFolder); if (parentFolder != null) { ifod.SetFolder(parentFolder); } } }