Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF-Callable Folder Browser Source Code [modified]

WPF-Callable Folder Browser Source Code [modified]

Scheduled Pinned Locked Moved WPF
csharpwpfcomlinuxdata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #1

    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
    
    P J 2 Replies Last reply
    0
    • M Mark Salsbery

      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
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Nicely done there sir. Nice code....

      Deja View - the feeling that you've seen this post before.

      My blog | My articles | MoXAML PowerToys

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        Nicely done there sir. Nice code....

        Deja View - the feeling that you've seen this post before.

        My blog | My articles | MoXAML PowerToys

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        • M Mark Salsbery

          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
          
          J Offline
          J Offline
          Jammer 0
          wrote on last edited by
          #4

          Nice!!!

          Jammer My Blog | Article(s)

          M 1 Reply Last reply
          0
          • J Jammer 0

            Nice!!!

            Jammer My Blog | Article(s)

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            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:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups