FolderBrowserDialog with input field

I'm not sure what to do here to explain what I want to do, so I will try here: I use both OpenFileDialog and FolderBrowserDialog in my code to view files and directories, respectively.

When the dialogs open, the user gets only the ability to actually view the file / directory tree. However, on trees with many directories and subdirectories, users would also like to be able to manually implicitly write (or paste) the full path to which to go.

How can I implement it in code?

Here are two functions that use dialog boxes:

Using FolderBrowserDialog:

  private void buttonAddDirectory_Click(object sender, EventArgs e) { this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); folderBrowserDialog.SelectedPath = "C:\\"; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { string selectedPath = folderBrowserDialog.SelectedPath; if (!searchForFiles(selectedPath)) { MessageBox.Show("The directory: " + selectedPath + " doesn't contain sequences.", "Error!"); return; } testForm.enableNumOfProcesses(); createNewCommand(runBatchScript, selectedPath, true); } } 

Using OpenFileDialog:

  private void buttonAddFile_Click(object sender, EventArgs e) { this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = "C:\\"; openFileDialog.Filter = "PMD files (*" + sequenceExtenssion + ")|*" + sequenceExtenssion + "|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string selectedFile = openFileDialog.FileName; if (Path.GetExtension(selectedFile).CompareTo(sequenceExtenssion) != 0) { MessageBox.Show("The file: " + selectedFile + " is not a sequence file.", "Error!"); return; } createNewCommand(batchRunExe, selectedFile, false); } } 
+8
c # forms openfiledialog folderbrowserdialog file-browser
source share
1 answer

Depending on the OS your user is using, this is done differently:

  • Windows 7, Vista, XP, etc. - you can simply enter metacommands (for example, D: in the input File name , and this meta-command will be executed. Or you can simply put your path in the box at the top (you need to click on it to switch from the navigation view to the input view)

  • If you use Mono, and some other standard GUI dialogs may not provide this functionality at all, you will have to implement these dialogs yourself.

0
source share

All Articles