csharp open file dialog

Code Example - csharp open file dialog

                
                        OpenFileDialog dialog = new OpenFileDialog();
if (DialogResult.OK == dialog.ShowDialog()) 
{
    string path = dialog.FileName;
}
                    
                
 

csharp winforms select folder dialogue

                        
                                using(var fbd = new FolderBrowserDialog())
{
    DialogResult result = fbd.ShowDialog();

    if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
    {
        string[] files = Directory.GetFiles(fbd.SelectedPath);

        System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
    }
}
                            
                        
 

csharp file directory selection

                        
                                CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.InitialDirectory = "C:\\Users";
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
    MessageBox.Show("You selected: " + dialog.FileName);
}
                            
                        
 

OpenFileDialog csharp

                        
                                OpenFileDialog fileDialog= new OpenFileDialog(); 
fileDialog.DefaultExt = ".txt"; // Required file extension 
fileDialog.Filter = "Text documents (.txt)|*.txt"; // Optional file extensions

fileDialog.ShowDialog();
                            
                        
 

open folder dialog csharp

                        
                                // https://github.com/ookii-dialogs/ookii-dialogs-wpf
string path;
var fbd = new VistaFolderBrowserDialog();
fbd.ShowNewFolderButton = true;
fbd.Description = "Select Source Folder";
fbd.ShowDialog();
path = fbd.SelectedPath;
//Fix Length Browse Folder Disk
return path.Length > 3 ? $@"{path}\" : $@"{path}";