Home >Backend Development >C++ >How to Select a Folder Efficiently in C# Using FolderBrowserDialog?
While the OpenFileOrFolderDialog project using the GetOpenFileName function is useful, it requires the attachment of a res1.rc file and dialog initialization, which can cause problems.
Another way to select a folder using OpenFileDialog is to use the FolderBrowserDialog class. This dialog box provides an easy-to-use folder selection interface.
Use FolderBrowserDialog:
<code class="language-csharp">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.Length.ToString(), "消息"); } }</code>
Key points:
The above is the detailed content of How to Select a Folder Efficiently in C# Using FolderBrowserDialog?. For more information, please follow other related articles on the PHP Chinese website!