WPF-Callable Folder Browser Source Code [modified]
-
Here's a simple wrapper around the SHBrowseForFolder() shell function.
*EDIT* Updated with more features!
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;namespace CommonDialogWrappers
{
/// <summary>
/// Represents a common dialog box (Win32::SHBrowseForFolder()) that allows a user to select a folder.
/// </summary>
public class BrowseForFolderDialog
{
#region Public Properties/// <summary> /// Gets the current and or final selected folder path. /// </summary> public string SelectedFolder { get; protected set; } /// <summary> /// Gets or sets the string that is displayed above the tree view control in the dialog box (must set BEFORE calling ShowDialog()). /// </summary> public string Title { get { return BrowseInfo.lpszTitle; } set { BrowseInfo.lpszTitle = value; } } /// <summary> /// Gets or sets the initially selected folder path. /// </summary> public string InitialFolder { get; set; } /// <summary> /// Gets or sets the initially selected and expanded folder path. Overrides SelectedFolder. /// </summary> public string InitialExpandedFolder { get; set; } /// <summary> /// Gets or sets the text for the dialog's OK button. /// </summary> public string OKButtonText { get; set; } BROWSEINFOW browseInfo; /// <summary> /// Provides direct access to the Win32::SHBrowseForFolder() BROWSEINFO structure used to create the dialog in ShowDialog(). /// </summary> public BROWSEINFOW BrowseInfo { get { return browseInfo; } protected set { browseInfo = value; } } /// <summary> /// Provides direct access to the ulFlags field of the Win32::SHBrowseForFolder() structure used to create the dialog in ShowDialog(). /// </summary> public BrowseInfoFlags BrowserDialogFlags { get { return BrowseInfo.ulFlags; } set { BrowseInfo.ulFlags = value; } } #endregion #region Public Constructors /// <summary> /// Constructs a BrowseForFolderDialog with default BrowseInfoFla
-
Here's a simple wrapper around the SHBrowseForFolder() shell function.
*EDIT* Updated with more features!
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;namespace CommonDialogWrappers
{
/// <summary>
/// Represents a common dialog box (Win32::SHBrowseForFolder()) that allows a user to select a folder.
/// </summary>
public class BrowseForFolderDialog
{
#region Public Properties/// <summary> /// Gets the current and or final selected folder path. /// </summary> public string SelectedFolder { get; protected set; } /// <summary> /// Gets or sets the string that is displayed above the tree view control in the dialog box (must set BEFORE calling ShowDialog()). /// </summary> public string Title { get { return BrowseInfo.lpszTitle; } set { BrowseInfo.lpszTitle = value; } } /// <summary> /// Gets or sets the initially selected folder path. /// </summary> public string InitialFolder { get; set; } /// <summary> /// Gets or sets the initially selected and expanded folder path. Overrides SelectedFolder. /// </summary> public string InitialExpandedFolder { get; set; } /// <summary> /// Gets or sets the text for the dialog's OK button. /// </summary> public string OKButtonText { get; set; } BROWSEINFOW browseInfo; /// <summary> /// Provides direct access to the Win32::SHBrowseForFolder() BROWSEINFO structure used to create the dialog in ShowDialog(). /// </summary> public BROWSEINFOW BrowseInfo { get { return browseInfo; } protected set { browseInfo = value; } } /// <summary> /// Provides direct access to the ulFlags field of the Win32::SHBrowseForFolder() structure used to create the dialog in ShowDialog(). /// </summary> public BrowseInfoFlags BrowserDialogFlags { get { return BrowseInfo.ulFlags; } set { BrowseInfo.ulFlags = value; } } #endregion #region Public Constructors /// <summary> /// Constructs a BrowseForFolderDialog with default BrowseInfoFla
Nicely done there sir. Nice code....
Deja View - the feeling that you've seen this post before.
-
Nicely done there sir. Nice code....
Deja View - the feeling that you've seen this post before.
Heh thanks. I think the only comments are the ones copied from SDK headers. I matched the ShowDialog prototypes to Microsoft.Win32.OpenFileDialog's ShowDialog() methods, hence the Nullable<bool> return type.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Here's a simple wrapper around the SHBrowseForFolder() shell function.
*EDIT* Updated with more features!
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;namespace CommonDialogWrappers
{
/// <summary>
/// Represents a common dialog box (Win32::SHBrowseForFolder()) that allows a user to select a folder.
/// </summary>
public class BrowseForFolderDialog
{
#region Public Properties/// <summary> /// Gets the current and or final selected folder path. /// </summary> public string SelectedFolder { get; protected set; } /// <summary> /// Gets or sets the string that is displayed above the tree view control in the dialog box (must set BEFORE calling ShowDialog()). /// </summary> public string Title { get { return BrowseInfo.lpszTitle; } set { BrowseInfo.lpszTitle = value; } } /// <summary> /// Gets or sets the initially selected folder path. /// </summary> public string InitialFolder { get; set; } /// <summary> /// Gets or sets the initially selected and expanded folder path. Overrides SelectedFolder. /// </summary> public string InitialExpandedFolder { get; set; } /// <summary> /// Gets or sets the text for the dialog's OK button. /// </summary> public string OKButtonText { get; set; } BROWSEINFOW browseInfo; /// <summary> /// Provides direct access to the Win32::SHBrowseForFolder() BROWSEINFO structure used to create the dialog in ShowDialog(). /// </summary> public BROWSEINFOW BrowseInfo { get { return browseInfo; } protected set { browseInfo = value; } } /// <summary> /// Provides direct access to the ulFlags field of the Win32::SHBrowseForFolder() structure used to create the dialog in ShowDialog(). /// </summary> public BrowseInfoFlags BrowserDialogFlags { get { return BrowseInfo.ulFlags; } set { BrowseInfo.ulFlags = value; } } #endregion #region Public Constructors /// <summary> /// Constructs a BrowseForFolderDialog with default BrowseInfoFla
-
Nice!!!
Jammer My Blog | Article(s)
Thanks! I updated the post to include all the features of the common dialog (and <summary> info ripped from the SDK;. Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: