Dialog to Ask Directory Path - CSharp System.IO

CSharp examples for System.IO:DirectoryInfo

Description

Dialog to Ask Directory Path

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Collections.Generic;
using System;//from w ww .ja v  a 2  s  .  c  o m

public class Main{
        public static string AskDirectoryPath(string InitialDirectory = "")
        {
            FolderBrowserDialog fd = new FolderBrowserDialog();
            fd.ShowNewFolderButton = true;

            if (InitialDirectory != "")
                fd.SelectedPath = InitialDirectory;

            if (fd.ShowDialog() == DialogResult.OK)
                return fd.SelectedPath;
            else
                return InitialDirectory;
        }
}

Related Tutorials