protected void SelectWalletFolder(object sender, EventArgs e) { SelectFolderDialog folderDialog = new SelectFolderDialog(); if (folderDialog.ShowDialog(this) == DialogResult.Ok) { SettingsViewModel viewModel = (SettingsViewModel)DataContext; viewModel.WalletFolder = folderDialog.Directory; } }
Control SelectFolder () { var button = new Button { Text = "Select Folder" }; button.Click += delegate { var dialog = new SelectFolderDialog (); var result = dialog.ShowDialog (this.ParentWindow); if (result == DialogResult.Ok) { Log.Write (dialog, "Result: {0}, Folder: {1}", result, dialog.Directory); } else Log.Write (dialog, "Result: {0}", result); }; return button; }
Control SelectFolderWithStartupPath() { var button = new Button { Text = "Select Folder With Initial Folder" }; button.Click += delegate { var dialog = new SelectFolderDialog(); dialog.Directory = Directory.GetCurrentDirectory(); var result = dialog.ShowDialog(ParentWindow); if (result == DialogResult.Ok) { Log.Write(dialog, "Result: {0}, Folder: {1}", result, dialog.Directory); } else Log.Write(dialog, "Result: {0}", result); }; return button; }
void OnButtonSelectPathClick(object sender, EventArgs e) { if (Filters != null) { // Handle file selection using (var dialog = new OpenFileDialog()) { foreach (var filter in Filters) { dialog.Filters.Add(filter); } if (TextBoxPath.Text.Length != 0) { var fileInfo = new FileInfo(TextBoxPath.Text); if (fileInfo.Exists) { Debug.Assert(fileInfo.DirectoryName != null, "fileInfo.DirectoryName != null"); dialog.Directory = new Uri(fileInfo.DirectoryName); } else { dialog.Directory = new Uri(Utilities.ApplicationBaseDirectory); } } if (dialog.ShowDialog(this) == DialogResult.Ok) { TextBoxPath.Text = Utilities.GetRelativePath(dialog.FileName); } } } else { // Handle directory selection using (var dialog = new SelectFolderDialog()) { if (TextBoxPath.Text.Length != 0) { var directory = Utilities.GetAbsolutePath(TextBoxPath.Text); if (Directory.Exists(directory)) dialog.Directory = directory; } if (dialog.ShowDialog(this) == DialogResult.Ok) { TextBoxPath.Text = Utilities.GetRelativePath(dialog.Directory); } } } TextBoxPath.SelectAll(); TextBoxPath.Focus(); }
Control SelectFolderWithStartupPath() { var button = new Button { Text = "Select Folder With Initial Folder" }; button.Click += delegate { var dialog = new SelectFolderDialog(); #if PCL dialog.Directory = EtoEnvironment.GetFolderPath(EtoSpecialFolder.Documents); #else dialog.Directory = Directory.GetCurrentDirectory(); #endif var result = dialog.ShowDialog(ParentWindow); if (result == DialogResult.Ok) { Log.Write(dialog, "Result: {0}, Folder: {1}", result, dialog.Directory); } else Log.Write(dialog, "Result: {0}", result); }; return button; }
/// <summary> /// Display an folder selection dialog and returns the selected folder name, null otherwise. /// </summary> /// <param name="windowTitle">Window title.</param> /// <returns>Selected folder name, null otherwise</returns> public static string SelectFolder(string windowTitle = "Select folder") { string folderPath = null; using (SelectFolderDialog dialog = new SelectFolderDialog()) { dialog.Title = windowTitle; var result = dialog.ShowDialog(null); if (result == DialogResult.Ok) folderPath = dialog.Directory; } return folderPath; }