Simple file dialog
String[] showFileDialog() { OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = "."; // Preselect .txt files dialog.Filter = "Txt-Dateien|*.txt"; dialog.FilterIndex = 1; dialog.Multiselect = false; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { return dialog.FileNames[0]; } }
Shows a simple dialog to pick a file from the local filesystem. In this snippet, only .txt files are preselected.
Most popular snippets