LitDev.LDDialogs.GetFolder C# (CSharp) Method

GetFolder() public static method

A Dialog to get a folder (directory).
public static GetFolder ( Primitive InitialFolder ) : Primitive
InitialFolder Primitive The initial folder or "" for the last folder selected.
return Primitive
        public static Primitive GetFolder(Primitive InitialFolder)
        {
            Primitive result = "";
            try
            {
                ThreadStart start = delegate
                {
                    System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
                    dlg.RootFolder = Environment.SpecialFolder.MyComputer;
                    dlg.SelectedPath = LastFolder;
                    if (InitialFolder != "") dlg.SelectedPath = InitialFolder;
                    if (dlg.ShowDialog(Utilities.ForegroundHandle()) == System.Windows.Forms.DialogResult.OK)
                    {
                        result = dlg.SelectedPath;
                        LastFolder = result;
                    }
                };
                Thread thread = new Thread(start);
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                StartPosition(null, "Browse For Folder");
                thread.Join();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return result;
        }