private void OnOutputPathButtonClick(object sender, RoutedEventArgs e) { string path = string.Empty; if (CommonFileDialog.IsPlatformSupported) { using (CommonOpenFileDialog dialog = new CommonOpenFileDialog()) { dialog.IsFolderPicker = true; dialog.Multiselect = false; dialog.DefaultDirectory = this.OutputPathBox.Text; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { path = dialog.FileName; } } } else { using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { dialog.RootFolder = Environment.SpecialFolder.MyMusic; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = dialog.SelectedPath; } } } extractor.OutputPath = path; }
private void ChooseDataPath() { var dialog = new CommonOpenFileDialog { IsFolderPicker = true, InitialDirectory = Settings.Default.DataPath }; var result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { var particleDir = Path.Combine(dialog.FileName, "art", "meshes", "Particle"); if (!Directory.Exists(particleDir)) { MessageBox.Show("The chosen data directory does not seem to be valid.\n" + "Couldn't find subdirectory art\\meshes\\Particle.", "Invalid Data Directory"); return; } Settings.Default.DataPath = dialog.FileName; Settings.Default.Save(); PreviewControl.DataPath = dialog.FileName; } }
internal FileOpenModalDialog(IDispatcherService dispatcher) : base(dispatcher) { Dialog = new CommonOpenFileDialog { EnsureFileExists = true }; Filters = new List<FileDialogFilter>(); FilePaths = new List<string>(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { //var dialog = new System.Windows.Forms.FolderBrowserDialog(); //System.Windows.Forms.DialogResult result = dialog.ShowDialog(); //// Configure open file dialog box //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); //dlg.FileName = "Document"; // Default file name //dlg.DefaultExt = ".txt"; // Default file extension //dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension //// Show open file dialog box //Nullable<bool> result = dlg.ShowDialog(); //// Process open file dialog box results //if (result == true) //{ // // Open document // string filename = dlg.FileName; //} //Check to see if the user is >Vista if (CommonFileDialog.IsPlatformSupported) { var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { dirName = dialog.FileName; textbox.Text = dirName; } } }
public static string BrowseForFolder(string startingPath) { string initialDirectory = _lastDirectory ?? startingPath; string ret = null; try { var cfd = new CommonOpenFileDialog { InitialDirectory = initialDirectory, IsFolderPicker = true }; if (cfd.ShowDialog() == CommonFileDialogResult.Ok) { ret = cfd.FileName; } } catch (System.PlatformNotSupportedException) { var fd = new System.Windows.Forms.FolderBrowserDialog { SelectedPath = initialDirectory }; if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ret = fd.SelectedPath; } } _lastDirectory = ret; return ret; }
public string ShowFolderBrowserDialog() { using (CommonOpenFileDialog dialog = new CommonOpenFileDialog { IsFolderPicker = true }) { return dialog.ShowDialog() == CommonFileDialogResult.Ok ? dialog.FileName : null; } }
private void OpenFileDialogCustomizationClicked(object sender, RoutedEventArgs e) { CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog(); currentFileDialog = openFileDialog; ApplyOpenDialogSettings(openFileDialog); // set the 'allow multi-select' flag openFileDialog.Multiselect = true; openFileDialog.EnsureFileExists = true; AddOpenFileDialogCustomControls(openFileDialog); CommonFileDialogResult result = openFileDialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { string output = ""; foreach (string fileName in openFileDialog.FileNames) { output += fileName + Environment.NewLine; } output += Environment.NewLine + GetCustomControlValues(); MessageBox.Show(output, "Files Chosen", MessageBoxButton.OK, MessageBoxImage.Information ); } }
private async void ImportImages() { var dialog = new CommonOpenFileDialog(); dialog.Filters.Add(new CommonFileDialogFilter("Images", "png,gif,jpg,jpeg,bmp")); dialog.Title = "Select Images"; dialog.EnsureFileExists = true; dialog.EnsurePathExists = true; dialog.EnsureReadOnly = false; dialog.EnsureValidNames = true; dialog.Multiselect = true; dialog.ShowPlacesList = true; if (dialog.ShowDialog() != CommonFileDialogResult.Ok) return; var images = dialog.FileNames .Where(p => System.IO.File.Exists(p)) .Select(p => PromptImage(new BitmapImage(new Uri(p)), p)) .Where(m => m != null) .ToList(); var reporter = new Progress<ProgressDialogState>(); var stopwatch = new Stopwatch(); var progress = ProgressDialog.Open(reporter, stopwatch); stopwatch.Start(); await _importer.AddImagesAsync(images, reporter); stopwatch.Stop(); progress.Close(); RefreshSheet(); }
// MainWindow newMain; // Global Declaration //// Run directory processing on a new thread //public async Task<string> getDirectory(MainWindow mainWindow) //{ // newMain = mainWindow; //} /////////////////////////////////////////////////////// // Select Directory Button Handler // - Gets full path including sub-directories // // - Uses string path = new DirButton().selectDirectory(); // - Output returns {string} path (selected in dialog) /////////////////////////////////////////////////////// public string selectDirectory() { // Define new MainWindow object (for reference) var mainWindow = ((MainWindow)System.Windows.Application.Current.MainWindow); // Begin Windows Dialog .DLL Extension usage var dlg = new CommonOpenFileDialog(); var currentDirectory = ""; dlg.Title = "Select Music Directory"; dlg.IsFolderPicker = true; dlg.InitialDirectory = currentDirectory; dlg.AddToMostRecentlyUsedList = false; dlg.AllowNonFileSystemItems = false; dlg.DefaultDirectory = currentDirectory; dlg.EnsureFileExists = true; dlg.EnsurePathExists = true; dlg.EnsureReadOnly = false; dlg.EnsureValidNames = true; dlg.Multiselect = false; dlg.ShowPlacesList = true; if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { string folder = dlg.FileName; //mainWindow.FileText.Text = folder; return folder; } else { return null; } }
private void onMenuSelected_SelectFileDownload(object sender, EventArgs e) { var items = this.listView.SelectedItems; IList<FileInfo> fileInfoList = new List<FileInfo>(); foreach (ListViewItem item in items) { fileInfoList.Add((FileInfo)item.Tag); } CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; dialog.EnsureReadOnly = false; dialog.Multiselect = false; dialog.AllowNonFileSystemItems = false; var result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { ProgressDialog progress = new ProgressDialog(); var context = TaskScheduler.FromCurrentSynchronizationContext(); Task task = Task.Factory.StartNew(() => { string dest = dialog.FileName; foreach (var fileInfo in fileInfoList) { PullFile(dest, fileInfo); } }); task.ContinueWith(x => { progress.Dispose(); RefreshFileList(); }, context); progress.ShowDialog(this); } }
private void InitializeDefaultSelections() { // Set filter options and filter index openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = GetFileDialogFilter(); openFileDialog.FilterIndex = 0; openFileDialog.Multiselect = true; // Set default input folder _mInputFolderDialog = new CommonOpenFileDialog(); _mInputFolderDialog.IsFolderPicker = true; _mInputFolderDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // Set default input format fileFormatComboBox.Items.AddRange(ConversionManager.GetSupportedFormats().ToArray()); fileFormatComboBox.SelectedIndex = 0; // Set default output folder _mOutputPathDialog = new CommonOpenFileDialog(); _mOutputPathDialog.IsFolderPicker = true; _mOutputPathDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); outputLocationTextBox.Text = _mOutputPathDialog.InitialDirectory; // Event handlers fileRadioButton.Click += fileRadioButton_isClicked; folderRadioButton.Click += folderRadioButton_isClicked; }
private void btnChooseKeyring_Click(object sender, RoutedEventArgs e) { using (var dlg = new CommonOpenFileDialog()) { dlg.Title = "Choose Keyring Folder"; dlg.IsFolderPicker = true; dlg.AddToMostRecentlyUsedList = false; dlg.AllowNonFileSystemItems = false; dlg.EnsureFileExists = true; dlg.EnsurePathExists = true; dlg.EnsureReadOnly = false; dlg.EnsureValidNames = true; dlg.Multiselect = false; dlg.ShowPlacesList = true; var oldPath = keyringPath.Text; if (File.Exists(oldPath)) { dlg.InitialDirectory = System.IO.Path.GetDirectoryName(oldPath); } if (dlg.ShowDialog(this) == CommonFileDialogResult.Ok) { keyringPath.Text = dlg.FileName; } } }
// Browse to select output file. private void CmdSelectOutputFile_Click(object sender, RoutedEventArgs e) { var dlg = new CommonOpenFileDialog(); dlg.Title = "Choose Entity Download File"; dlg.IsFolderPicker = false; //dlg.InitialDirectory = currentDirectory; dlg.AddToMostRecentlyUsedList = false; dlg.AllowNonFileSystemItems = false; //dlg.DefaultDirectory = currentDirectory; dlg.EnsureFileExists = false; dlg.EnsurePathExists = true; dlg.EnsureReadOnly = false; dlg.EnsureValidNames = true; dlg.Multiselect = false; dlg.ShowPlacesList = true; dlg.Filters.Add(new CommonFileDialogFilter("CSV File (*.csv)", ".csv")); dlg.Filters.Add(new CommonFileDialogFilter("JSON File (*.json)", ".json")); dlg.Filters.Add(new CommonFileDialogFilter("XML File (*.xml)", ".xml")); if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { OutputFile.Focus(); OutputFile.Text = dlg.FileName; } }
// Lets the user choose and upload an image from file to the blob storage. // The file is saved under the name "User[id]img". // The method then calls the GetImage() method to display the uploaded image. private async void BtnUserImage_Click(object sender, RoutedEventArgs e) { var cofd = new CommonOpenFileDialog(); cofd.Filters.Add(new CommonFileDialogFilter("JPEG Files", "*.jpg")); cofd.Filters.Add(new CommonFileDialogFilter("PNG Files", "*.png")); if (cofd.ShowDialog() == CommonFileDialogResult.Ok) { try { string name = "User" + selectedUID + "img"; CloudBlockBlob blockBlob = (App.Current as App).blobcontainer.GetBlockBlobReference(name); blockBlob.Properties.ContentType = "image/jpg"; using (var fileStream = System.IO.File.OpenRead(cofd.FileName)) { await blockBlob.UploadFromStreamAsync(fileStream); { GetImage(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "uploading or downloading image error"); } } }
internal FileOpenModalDialog(Dispatcher dispatcher, Window parentWindow) : base(dispatcher, parentWindow) { Dialog = new CommonOpenFileDialog { EnsureFileExists = true }; Filters = new List<FileDialogFilter>(); FilePaths = new List<string>(); }
private async void SelectRepoButtonClick(object sender, RoutedEventArgs e) { using (var dialog = new CommonOpenFileDialog()) { dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { commandFactory = new CommandFactory(resultCommandMapper, dialog.FileName); var statusCommand = commandFactory.GetCommand<StatusResult>(); statusCommand.Execute(); if (statusCommand.Result.ExecutionResult == ExecutionResult.NoRepository) { commandFactory = null; MessageBox.Show("The selected file contains no git repository.", "Error!", MessageBoxButton.OK); } else { currentBranch.Text = "Current branch: " + statusCommand.Result.CurrentBranch; } await ListNormalCommits(); } } }
private void btnOpen_Click( object sender, RoutedEventArgs e ) { CommonOpenFileDialog openDialog = new CommonOpenFileDialog(); openDialog.ShowPlacesList = true; openDialog.Multiselect = false; openDialog.IsFolderPicker = false; openDialog.AddToMostRecentlyUsedList = true; openDialog.Filters.Add( new CommonFileDialogFilter( "PNG images", "*.png" ) ); if ( openDialog.ShowDialog( this ) == CommonFileDialogResult.Ok ) { soureFilePath = openDialog.FileName; // get comment meta using ( FileStream fileStream = new FileStream( soureFilePath, FileMode.Open, FileAccess.Read ) ) { pngReader = new PngReader( fileStream ); // 参考自Hjg.Pngcs的SampleCustomChunk项目 // get last line: this forces loading all chunks pngReader.ReadChunksOnly(); tblkComment.Text = pngReader.GetMetadata().GetTxtForKey( Key_SemanticInfo ); pngReader.End(); fileStream.Close(); } image.BeginInit(); image.Source = new BitmapImage( new Uri( soureFilePath ) ); image.EndInit(); } }
public static GameLocationInfo GetGameLocation(FFXIIIGamePart gamePart) { try { using (RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) using (RegistryKey registryKey = localMachine.OpenSubKey(GetSteamRegistyPath(gamePart))) { if (registryKey == null) throw Exceptions.CreateException("Запись в реестре не обнаружена."); GameLocationInfo result = new GameLocationInfo((string)registryKey.GetValue(GameLocationSteamRegistryProvider.SteamGamePathTag)); result.Validate(); return result; } } catch { return Application.Current.Dispatcher.Invoke(() => { using (CommonOpenFileDialog dlg = new CommonOpenFileDialog(String.Format("Укажите каталог Final Fantasy XIII-{0}...", (int)gamePart))) { dlg.IsFolderPicker = true; if (dlg.ShowDialog() != CommonFileDialogResult.Ok) throw new OperationCanceledException(); GameLocationInfo result = new GameLocationInfo(dlg.FileName); result.Validate(); return result; } }); } }
public bool Run (AddFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; var dialog = new CommonOpenFileDialog (); SelectFileDialogHandler.SetCommonFormProperties (data, dialog); var buildActionCombo = new CommonFileDialogComboBox (); var group = new CommonFileDialogGroupBox ("overridebuildaction", "Override build action:"); buildActionCombo.Items.Add (new CommonFileDialogComboBoxItem (GettextCatalog.GetString ("Default"))); foreach (var ba in data.BuildActions) { if (ba == "--") continue; buildActionCombo.Items.Add (new CommonFileDialogComboBoxItem (ba)); } buildActionCombo.SelectedIndex = 0; group.Items.Add (buildActionCombo); dialog.Controls.Add (group); if (!GdkWin32.RunModalWin32Dialog (dialog, parent)) return false; SelectFileDialogHandler.GetCommonFormProperties (data, dialog); var idx = buildActionCombo.SelectedIndex; if (idx > 0) data.OverrideAction = buildActionCombo.Items [idx].Text; return true; }
public string SelectDirectoryDialog(string defaultPath, string title = null) { var dlg = new CommonOpenFileDialog() { Title = "", IsFolderPicker = true, InitialDirectory = defaultPath, AddToMostRecentlyUsedList = false, AllowNonFileSystemItems = false, DefaultDirectory = defaultPath, EnsureFileExists = true, EnsurePathExists = true, EnsureReadOnly = false, EnsureValidNames = true, Multiselect = false, ShowPlacesList = true }; if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { return dlg.FileName; } return null; }
private void browseSmfPath_Click(object sender, EventArgs e) { // Get us a new FolderBrowserDialog CommonOpenFileDialog fb = new CommonOpenFileDialog(); fb.IsFolderPicker = true; fb.Title = "Please select the directory that your environment resides in."; fb.EnsurePathExists = true; CommonFileDialogResult rs = fb.ShowDialog(); if (rs == CommonFileDialogResult.Cancel) return; // Get the path. string s = fb.FileName; if (Directory.Exists(s)) { smfPath.Text = s; if (File.Exists(s + "/index.php")) { string contents = File.ReadAllText(s + "/index.php"); Match match = Regex.Match(contents, @"'SMF ([^']*)'"); if (match.Success) dsmfver.Text = match.Groups[1].Value; else dsmfver.Text = "(unknown)"; } else dsmfver.Text = "(unknown)"; } }
public void SelectFiles() { if (CommonFileDialog.IsPlatformSupported) { var commonOpenFileDialog = new CommonOpenFileDialog("Select the audio files that you want to link to the zune social") { Multiselect = true, EnsureFileExists = true }; commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("Audio Files", "*.mp3;*.wma;*.m4a")); commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("MP3 Files", "*.mp3")); commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("WMA Files", "*.wma")); commonOpenFileDialog.Filters.Add(new CommonFileDialogFilter("Mpeg4 Files", "*.m4a")); if (commonOpenFileDialog.ShowDialog() == CommonFileDialogResult.OK) ReadFiles(commonOpenFileDialog.FileNames); } else { var ofd = new OpenFileDialog { Multiselect = true, Filter = "Audio files .mp3,.wma,.m4a |*.mp3;*.wma;*.m4a", AutoUpgradeEnabled = true, Title = "Select the audio files that you want to link to the zune social", CheckFileExists = true }; if (ofd.ShowDialog() == DialogResult.OK) ReadFiles(ofd.FileNames); } }
/// <summary> /// Constructs a new <see cref="FolderBrowserDialog3"/> instance. /// </summary> /// <exception cref="TypeInitializationException"> /// Thrown if the operating system is not Windows Vista or newer /// or if the user is running Mono. /// </exception> /// <exception cref="PlatformNotSupportedException"> /// Thrown if the operating system is not Windows Vista or newer /// or if the user is running Mono. /// </exception> public FolderBrowserDialog3() { _dialog = new CommonOpenFileDialog { EnsureReadOnly = true, IsFolderPicker = true, AllowNonFileSystemItems = false }; }
/// <summary> /// Initializes a new instance of the <see cref="CommonOpenFileFolderSelectionDialog"/> class. /// </summary> public CommonOpenFileFolderSelectionDialog() { this._commonOpenFileDialog = new CommonOpenFileDialog() { IsFolderPicker = true, Multiselect = false, }; this._defaultTitle = this._commonOpenFileDialog.Title; }
private void SelectScreenFolder(object sender, RoutedEventArgs e) { using (var folderdialog = new CommonOpenFileDialog()) { folderdialog.IsFolderPicker = true; folderdialog.InitialDirectory = Config.Current.ScreenShotFolder; if (folderdialog.ShowDialog() == CommonFileDialogResult.Ok) Config.Current.ScreenShotFolder = folderdialog.FileName; } }
private void BtnBrowse_click(object sender, RoutedEventArgs e) { var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { TextPath.Text = dialog.FileName; } }
private void selectDoelMap_Click(object sender, RoutedEventArgs e) { CodePack.CommonOpenFileDialog dialog = new CodePack.CommonOpenFileDialog(); //dialog.InitialDirectory = "C:\\Users\\mathi\\Documents\\testomgeving"; //! dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CodePack.CommonFileDialogResult.Ok) { _doelPad = dialog.FileName; doelMap.Text = dialog.FileName; } }
public Task<string> ShowOpenFileDialogAsync(string title, string defaultExtension, params Tuple<string, string>[] extensions) { var tcs = new TaskCompletionSource<string>(); _dispatcherService.CurrentDispatcher.BeginInvoke(new Action(() => { var result = string.Empty; // Create a CommonOpenFileDialog to select source file CommonOpenFileDialog cfd = new CommonOpenFileDialog { AllowNonFileSystemItems = true, EnsureReadOnly = true, EnsurePathExists = true, EnsureFileExists = true, DefaultExtension = defaultExtension, Multiselect = false, // One file at a time Title = title ?? "Select File", }; if ((extensions != null) && (extensions.Any())) { foreach (var ext in extensions) { cfd.Filters.Add(new CommonFileDialogFilter(ext.Item1, ext.Item2)); } } if (cfd.ShowDialog() == CommonFileDialogResult.Ok) { ShellObject selectedObj = null; try { // Try to get the selected item selectedObj = cfd.FileAsShellObject; } catch { //MessageBox.Show("Could not create a ShellObject from the selected item"); } if (selectedObj != null) { // Get the file name result = selectedObj.ParsingName; } } tcs.SetResult(result); })); return tcs.Task; }
private async void DoBrowseAvatar() { var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog(); var result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { var base64String = Convert.ToBase64String(await File.ReadAllBytesAsync(dialog.FileName)); Avatar = base64String; _isAvatarDirty = true; } }
private void SaveCmdExecuted(object sender, RoutedEventArgs e) { // Set up a folder browser var folderbrowserDialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog(); folderbrowserDialog.IsFolderPicker = true; // DialogResult result = dlg.ShowDialog(); if (folderbrowserDialog.ShowDialog() == CommonFileDialogResult.Ok) { OutputDirectory = folderbrowserDialog.FileName; } lblOutputFilePath.Content = OutputDirectory; }
private void buttonDepot_Click(object sender, EventArgs e) { using (var ofd = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog()) { ofd.IsFolderPicker = true; ofd.Multiselect = false; var rslt = ofd.ShowDialog(); if (rslt != CommonFileDialogResult.Ok) { return; } textBoxDepotPath.Text = ofd.FileName; } }
private string BrowseAndCheckForPath(ObservableCollection <Installation> installations) { using (var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog()) { dialog.IsFolderPicker = true; Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { string path = dialog.FileName; var same_pathed = installations.Where(x => x.Path.TrimEnd('\\') == path.TrimEnd('\\') && x.IsAutodiscoveredInstance == false); if (same_pathed.Count() > 0) { var ans = MessageBox.Show( $"You already have [{path}] in your user-added list. Do you really want to add it again [not recommended]?. Press No if you are not sure what to do.", Branding.MessageBoxHeader, MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No); if (ans == MessageBoxResult.No) { return(null); } } if (!(new Installation(path)).Detected) { var ans = MessageBox.Show( $"Cannot detect any {Branding.TargetProduct} installation in [{path}]. Do you really want to add this path? (No = Select another, Cancel = Add nothing)", Branding.MessageBoxHeader, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation, MessageBoxResult.No); if (ans == MessageBoxResult.Cancel) { return(null); } else if (ans == MessageBoxResult.No) { return(BrowseAndCheckForPath(installations)); } } return(path); } } return(null); }
public static bool OpenFolderDialog(Controls.TextBox tb, string initialDirectory) { bool success = false; var win32 = PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows; if (((int)Environment.OSVersion.Platform & (int)win32) >= 1) { using (var dlg = new Dialogs.CommonOpenFileDialog { InitialDirectory = initialDirectory, EnsurePathExists = true, IsFolderPicker = true, Title = "Select directory", AllowNonFileSystemItems = true }) { success = dlg.ShowDialog() == Dialogs.CommonFileDialogResult.Ok; if (success) { success &= !string.IsNullOrWhiteSpace(dlg.FileName); tb.Text = success ? dlg.FileName : string.Empty; } } } else { using (var dlg = new Forms.FolderBrowserDialog()) { if (dlg.ShowDialog() == Forms.DialogResult.OK && string.IsNullOrWhiteSpace(dlg.SelectedPath)) { tb.Text = dlg.SelectedPath; } } } if (!success) { MessageBox.Show("No folder selected"); } return(success); }
private void btnChoosePostInstallCommand_Click(object sender, RoutedEventArgs e) { bool oldTopMost = this.Topmost; this.Topmost = false; using (var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog()) { dialog.Filters.Add(new CommonFileDialogFilter("Executable files", "*.exe; *.com; *.bat; *.cmd; *.ps1; *.vbs; *.sh; *.ps2; *.jar")); dialog.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { txtPostInstallCommand.Text = dialog.FileName; } } this.Topmost = oldTopMost; }
public static CommonOpenFileDialog ToFileDialog(this CommonOpenFileDialog dialog) { dialog.IsFolderPicker = false; return(dialog); }
private static void AnotherReplayFolderCMDLink_Click( object s, EventArgs e ) { var openFolderDialog = new CommonOpenFileDialog(); openFolderDialog.Title = "Select the wargame3 replay folders"; openFolderDialog.IsFolderPicker = true; openFolderDialog.FileOk += ( sender, parameter ) => { var dialog = (CommonOpenFileDialog)sender; if ( !ReplayFolderPicker.ReplaysPathContainsReplay(dialog.FileName) ) { parameter.Cancel = true; MessageBox.Show("This folder doesn't contain any .wargamerpl2 files", "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); } }; CommonFileDialogResult result = openFolderDialog.ShowDialog(); if ( result == CommonFileDialogResult.Ok ) { _newPath = openFolderDialog.FileName; var s2 = (TaskDialogCommandLink)s; var taskDialog = (TaskDialog)(s2.HostingDialog); //taskDialog.Close(TaskDialogResult.CustomButtonClicked); } }
private void ButtonKeyClick(object sender, EventArgs e) { if (CommonOpenFileDialog.IsPlatformSupported) { using (CommonOpenFileDialog dialog = new CommonOpenFileDialog()) { dialog.Title = openFileDialogKey.Title; dialog.DefaultExtension = openFileDialogKey.DefaultExt; dialog.Filters.Add(new CommonFileDialogFilter("Key files", "*.snk;*.pfx")); dialog.EnsurePathExists = true; dialog.EnsureValidNames = true; dialog.IsFolderPicker = false; dialog.Multiselect = false; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { string selectedFolder = dialog.FileName; while (!Directory.Exists(selectedFolder)) { // Work around dialog bug in Vista. selectedFolder = Directory.GetParent(selectedFolder).FullName; } textBoxKey.Text = dialog.FileName; } } } else { if (openFileDialogKey.ShowDialog() == DialogResult.OK) { textBoxKey.Text = openFileDialogKey.FileName; } } }
/// <summary> /// Opens a folder browser dialog and returns the selected folders. /// </summary> /// <param name="owner">The owner for the dialog.</param> /// <returns>A list with the selected folders.</returns> public static IList<string> GetFolders(Window owner) { if (CommonFileDialog.IsPlatformSupported) { using (var dialog = new CommonOpenFileDialog()) { dialog.IsFolderPicker = true; dialog.Multiselect = true; var result = dialog.ShowDialog(owner); if (result == CommonFileDialogResult.Ok) { return dialog.FileNames.ToList(); } } } else { using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { var result = owner is System.Windows.Forms.IWin32Window ? dialog.ShowDialog((System.Windows.Forms.IWin32Window)owner) : dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { return new[] { dialog.SelectedPath }; } } } return Enumerable.Empty<string>().ToList(); }