Answers for "open folder dialog c#"

C#
5

c# open file dialog

OpenFileDialog dialog = new OpenFileDialog();
if (DialogResult.OK == dialog.ShowDialog()) 
{
    string path = dialog.FileName;
}
Posted by: Guest on July-16-2020
1

open file dialog c#

var fileContent = string.Empty;
var filePath = string.Empty;

using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
    openFileDialog.InitialDirectory = "c:\\";
    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog.FilterIndex = 2;
    openFileDialog.RestoreDirectory = true;

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
        //Get the path of specified file
        filePath = openFileDialog.FileName;

        //Read the contents of the file into a stream
        var fileStream = openFileDialog.OpenFile();

        using (StreamReader reader = new StreamReader(fileStream))
        {
            fileContent = reader.ReadToEnd();
        }
    }
}

MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
Posted by: Guest on September-27-2020
1

c# 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");
    }
}
Posted by: Guest on September-21-2020
-1

c# 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);
}
Posted by: Guest on August-05-2020
0

open folder dialog c#

// 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}";
Posted by: Guest on September-23-2021

C# Answers by Framework

Browse Popular Code Answers by Language