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); } }
c # forms openfiledialog folderbrowserdialog file-browser
Idanis
source share