Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

If you want to select a folder in a dialog in WPF, you can use the FolderBrowserDialog from Winforms.

To specify the first set folder when opening the dialog box, you must set the SelectedPath to do this without setting a RootFolder.

 

Directory selection, directory dialog with WPF

 

SelectPath

            //< Dialog >

            WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();

            folderDialog.ShowNewFolderButton = false;

            folderDialog.SelectedPath = "D:\\Videos\\_Import\\100OLYMP\\100OLYMP";

            WinForms.DialogResult result = folderDialog.ShowDialog();

            //</ Dialog >

 

            if (result == WinForms.DialogResult.OK)

            {

                //----< Selected Folder >----

                //< Selected Path >

                sPath = folderDialog.SelectedPath;

                tbxFolder.Text = sPath;

                Properties.Settings.Default.Folder_Path=sPath;

                //</ Selected Path >

 

                reload();

            }

 

SelectedPath:

View of the folder dialog when the default path is set.

 

 

Default RootFolder

 

If you can not specify a special folder, you should set the RootFolder as the default with a Windows system directory.

 

            //< Dialog >

            WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();

            folderDialog.ShowNewFolderButton = false;

            //no effect: folderDialog.SelectedPath = "D:\\Videos\\_Import\\100OLYMP\\100OLYMP";

            folderDialog.RootFolder = Environment.SpecialFolder.Desktop;

            WinForms.DialogResult result = folderDialog.ShowDialog();

            //</ Dialog >

 

            if (result == WinForms.DialogResult.OK)

            {

                //----< Selected Folder >----

                //< Selected Path >

                sPath = folderDialog.SelectedPath;

                tbxFolder.Text = sPath;

                Properties.Settings.Default.Folder_Path=sPath;

                //</ Selected Path >

 

                reload();

            }

 

RootFolder:

Folder dialog without default but set RootFolder, Environment.SpecialFolder

 

 

Namspace

To use the wpf Folderdialog you have to integrate the Winforms dialog.

//--< using >--

using Microsoft.Win32;                      //FileDialog

using WinForms = System.Windows.Forms;     //FolderDialog

//--</ using >--

 

Mobile
»
WPF: Explorer with path open
»
WPF: Open a Window at a position
»
WPF: Selection enter open and well take over with Button Elements
»
WPF: Select Folder with Startup Directory
»
WPF: FolderDialog and GetFiles
»
Error CS0234: The type or namespace name Forms does not exist in the namespace
»
WPF: Filedialog, OpenFileDialog

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de