<p>In VS .NET, when you are selecting a folder for a project, a dialog that looks like an OpenFileDialog or SaveFileDialog is displayed, but is set up to accept only folders.  Ever since I've seen this I've wanted to know how it's done.  I am aware of the FolderBrowserDialog, but I've never really liked that dialog.  It starts too small and doesn't let me take advantage of being able to type a path.</p>

<p>I'm almost certain by now there's not a way to do this from .NET, but I'm just as curious how you do it from unmanaged code as well.  Short of completely reimplementing the dialog from scratch, how do you modify the dialog to have this behavior?</p>

<p>I'd also like to restate that I am aware of the FolderBrowserDialog but sometimes I don't like to use it, in addition to being genuinely curious how to configure a dialog in this manner.  Telling me to just use the FolderBrowserDialog helps me maintain a consistent UI experience but doesn't satisfy my curiosity so it won't count as an answer.</p>

<p>It's not a Vista-specific thing either; I've been seeing this dialog since VS .NET 2003, so it is doable in Win2k and WinXP.  This is less of a "I want to know the proper way to do this" question and more of a "I have been curious about this since I first wanted to do it in VS 2003" question.  I understand that Vista's file dialog has an option to do this, but it's been working in XP so I know they did <em>something</em> to get it to work.  Vista-specific answers are not answers, because Vista doesn't exist in the question context.</p>

<p><strong>Update: I'm accepting Scott Wisniewski's answer because it comes with a working sample, but I think Serge deserves credit for pointing to the dialog customization (which is admittedly nasty from .NET but it <em>does</em> work) and Mark Ransom for figuring out that MS probably rolled a custom dialog for this task.</strong></p>

[{'answer_id': 31082, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 5, 'selected': False, 'text': '<p>Better to use the FolderBrowserDialog  for that.   </p>\n\n<pre><code>using (FolderBrowserDialog dlg = new FolderBrowserDialog())\n{\n    dlg.Description = "Select a folder";\n    if (dlg.ShowDialog() == DialogResult.OK)\n    {\n        MessageBox.Show("You selected: " + dlg.SelectedPath);\n    }\n}\n</code></pre>\n'}, {'answer_id': 31474, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 3, 'selected': False, 'text': '<p>I assume you\'re on Vista using VS2008? In that case I think that the <a href="http://msdn.microsoft.com/en-us/library/bb761832.aspx" rel="nofollow noreferrer">FOS_PICKFOLDERS option</a> is being used when calling the Vista file dialog <a href="http://msdn.microsoft.com/en-us/library/bb775966.aspx" rel="nofollow noreferrer">IFileDialog</a>. I\'m afraid that in .NET code this would involve plenty of gnarly P/Invoke interop code to get working.</p>\n'}, {'answer_id': 506298, 'author': 'Serge Wautier', 'author_id': 12379, 'author_profile': 'https://Stackoverflow.com/users/12379', 'pm_score': 4, 'selected': False, 'text': '<p>OK, let me try to connect the first dot ;-)\nPlaying a little bit with Spy++ or Winspector shows that the Folder textbox in the VS Project Location is a customization of the standard dialog. It\'s not the same field as the filename textbox in a standard file dialog such as the one in Notepad.</p>\n\n<p>From there on, I figure, VS hides the filename and filetype textboxes/comboboxes and uses a custom dialog template to add its own part in the bottom of the dialog.</p>\n\n<p>EDIT: Here\'s an example of such customization and how to do it (in Win32. not .NET):</p>\n\n<p>m_ofn is the OPENFILENAME struct that underlies the file dialog. Add these 2 lines:</p>\n\n<pre><code>  m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEDIALOG_IMPORTXLIFF);\n  m_ofn.Flags |= OFN_ENABLETEMPLATE;\n</code></pre>\n\n<p>where IDD_FILEDIALOG_IMPORTXLIFF is a custom dialog template that will be added in the bottom of the dialog. See the part in red below. \n<a href="https://i.stack.imgur.com/68F6i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/68F6i.png" alt="alt text"></a><br>\n<sub>(source: <a href="http://apptranslator.com/_so/customizedfiledialog.png" rel="nofollow noreferrer">apptranslator.com</a>)</sub>  </p>\n\n<p>In this case, the customized part is only a label + an hyperlink but it could be any dialog. It could contain an OK button that would let us validate folder only selection.</p>\n\n<p>But how we would get rid of some of the controls in the standard part of the dialog, I don\'t know.</p>\n\n<p>More detail in <a href="http://msdn.microsoft.com/en-us/library/ms646960%28VS.85%29.aspx" rel="nofollow noreferrer">this MSDN article</a>.</p>\n'}, {'answer_id': 506364, 'author': 'demoncodemonkey', 'author_id': 61697, 'author_profile': 'https://Stackoverflow.com/users/61697', 'pm_score': 1, 'selected': False, 'text': '<p>Try this one from <a href="http://www.codeproject.com/KB/cpp/BrowseForFolder.aspx" rel="nofollow noreferrer">Codeproject</a> (credit to Nitron):</p>\n\n<p>I think it\'s the same dialog you\'re talking about - maybe it would help if you add a screenshot?</p>\n\n<pre><code>bool GetFolder(std::string&amp; folderpath, const char* szCaption=NULL, HWND hOwner=NULL)\n{\n    bool retVal = false;\n\n    // The BROWSEINFO struct tells the shell how it should display the dialog.\n    BROWSEINFO bi;\n    memset(&amp;bi, 0, sizeof(bi));\n\n    bi.ulFlags   = BIF_USENEWUI;\n    bi.hwndOwner = hOwner;\n    bi.lpszTitle = szCaption;\n\n    // must call this if using BIF_USENEWUI\n    ::OleInitialize(NULL);\n\n    // Show the dialog and get the itemIDList for the selected folder.\n    LPITEMIDLIST pIDL = ::SHBrowseForFolder(&amp;bi);\n\n    if(pIDL != NULL)\n    {\n        // Create a buffer to store the path, then get the path.\n        char buffer[_MAX_PATH] = {\'\\0\'};\n        if(::SHGetPathFromIDList(pIDL, buffer) != 0)\n        {\n            // Set the string value.\n            folderpath = buffer;\n            retVal = true;\n        }       \n\n        // free the item id list\n        CoTaskMemFree(pIDL);\n    }\n\n    ::OleUninitialize();\n\n    return retVal;\n}\n</code></pre>\n'}, {'answer_id': 509103, 'author': 'Jeff Yates', 'author_id': 23234, 'author_profile': 'https://Stackoverflow.com/users/23234', 'pm_score': 3, 'selected': False, 'text': '<p>You can subclass the file dialog and gain access to all its controls. Each has an identifier that can be used to obtain its window handle. You can then show and hide them, get messages from them about selection changes etc. etc. It all depends how much effort you want to take.</p>\n\n<p>We did ours using WTL class support and customized the file dialog to include a custom places bar and plug-in COM views.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms646960(VS.85).aspx" rel="noreferrer">MSDN</a> provides information on how to do this using Win32, <a href="http://www.codeproject.com/KB/dialog/customize_dialog.aspx" rel="noreferrer">this CodeProject article includes an example</a>, and <a href="http://www.codeproject.com/KB/dialog/CustomizeFileDialog.aspx" rel="noreferrer">this CodeProject article provides a .NET example</a>.</p>\n'}, {'answer_id': 510035, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://www.exactaudiocopy.de/" rel="noreferrer">Exact Audio Copy</a> works this way on Windows XP.  The standard file open dialog is shown, but the filename field contains the text "Filename will be ignored".</p>\n\n<p>Just guessing here, but I suspect the string is injected into the combo box edit control every time a significant change is made to the dialog. As long as the field isn\'t blank, and the dialog flags are set to not check the existence of the file, the dialog can be closed normally.</p>\n\n<p><b>Edit:</b> this is much easier than I thought.  Here\'s the code in C++/MFC, you can translate it to the environment of your choice.</p>\n\n<pre><code>CFileDialog dlg(true, NULL, "Filename will be ignored", OFN_HIDEREADONLY | OFN_NOVALIDATE | OFN_PATHMUSTEXIST | OFN_READONLY, NULL, this);\ndlg.DoModal();\n</code></pre>\n\n<p><b>Edit 2:</b> This should be the translation to C#, but I\'m not fluent in C# so don\'t shoot me if it doesn\'t work.</p>\n\n<pre><code>OpenFileDialog openFileDialog1 = new OpenFileDialog();\n\nopenFileDialog1.FileName = "Filename will be ignored";\nopenFileDialog1.CheckPathExists = true;\nopenFileDialog1.ShowReadOnly = false;\nopenFileDialog1.ReadOnlyChecked = true;\nopenFileDialog1.CheckFileExists = false;\nopenFileDialog1.ValidateNames = false;\n\nif(openFileDialog1.ShowDialog() == DialogResult.OK)\n{\n    // openFileDialog1.FileName should contain the folder and a dummy filename\n}\n</code></pre>\n\n<p><b>Edit 3:</b> Finally looked at the actual dialog in question, in Visual Studio 2005 (I didn\'t have access to it earlier). <b>It is not the standard file open dialog!</b> If you inspect the windows in Spy++ and compare them to a standard file open, you\'ll see that the structure and class names don\'t match. When you look closely, you can also spot some differences between the contents of the dialogs. My conclusion is that Microsoft completely replaced the standard dialog in Visual Studio to give it this capability. My solution or something similar will be as close as you can get, unless you\'re willing to code your own from scratch.</p>\n'}, {'answer_id': 511161, 'author': 'Christian Klauser', 'author_id': 55208, 'author_profile': 'https://Stackoverflow.com/users/55208', 'pm_score': 5, 'selected': False, 'text': '<p>The <a href="https://github.com/ookii-dialogs/" rel="nofollow noreferrer">Ookii.Dialogs</a> package contains a managed wrapper around the new (Vista-style) folder browser dialog. It also degrades gracefully on older operating systems.</p>\n<ul>\n<li><a href="https://github.com/augustoproiete/ookii-dialogs-wpf" rel="nofollow noreferrer">Ookii Dialogs for WPF</a> targetting .NET 4.5 and <a href="https://www.nuget.org/packages/Ookii.Dialogs.Wpf/" rel="nofollow noreferrer">available on NuGet</a></li>\n<li><a href="https://github.com/augustoproiete/ookii-dialogs-winforms" rel="nofollow noreferrer">Ookii Dialogs for Windows Forms</a> targetting .NET 4.5 and <a href="https://www.nuget.org/packages/Ookii.Dialogs.WinForms/" rel="nofollow noreferrer">available on NuGet</a></li>\n</ul>\n'}, {'answer_id': 514258, 'author': 'Avram', 'author_id': 61883, 'author_profile': 'https://Stackoverflow.com/users/61883', 'pm_score': 3, 'selected': False, 'text': '<p>You can use code like this<br></p>\n\n<ul>\n<li>The filter is hide files<br> </li>\n<li>The filename is hide first text<br></li>\n</ul>\n\n<p>To advanced hide of textbox for filename you need to look at \n<a href="http://www.codeproject.com/KB/dialog/OpenFileDialogEx.aspx" rel="noreferrer">OpenFileDialogEx</a><br></p>\n\n<p>The code:<br></p>\n\n<pre><code>{\n    openFileDialog2.FileName = "\\r";\n    openFileDialog1.Filter = "folders|*.neverseenthisfile";\n    openFileDialog1.CheckFileExists = false;\n    openFileDialog1.CheckPathExists = false;\n}\n</code></pre>\n'}, {'answer_id': 514368, 'author': 'Scott Wisniewski', 'author_id': 1737192, 'author_profile': 'https://Stackoverflow.com/users/1737192', 'pm_score': 7, 'selected': True, 'text': '<p>I have a dialog that I wrote called an OpenFileOrFolder dialog that allows you to open either a folder or a file.</p>\n\n<p>If you set its AcceptFiles value to false, then it operates in only accept folder mode.</p>\n\n<p><a href="https://github.com/scottwis/OpenFileOrFolderDialog" rel="noreferrer">You can download the source from GitHub here</a></p>\n'}, {'answer_id': 625069, 'author': 'Cheeso', 'author_id': 48082, 'author_profile': 'https://Stackoverflow.com/users/48082', 'pm_score': 6, 'selected': False, 'text': '<p>You can use <a href="https://github.com/jkells/folder-browser-dialog-example/blob/master/FolderBrowserDialogEx.cs" rel="nofollow noreferrer">FolderBrowserDialogEx</a> - \na re-usable derivative of the built-in FolderBrowserDialog.  This one allows you to type in a path, even a UNC path.  You can also browse for computers or printers with it.  Works just like the built-in FBD, but ... better. </p>\n\n<p>(EDIT: I should have pointed out that this dialog can be set to select files or folders. )</p>\n\n<p>Full Source code (one short C# module). Free.  MS-Public license.</p>\n\n<p>Code to use it: </p>\n\n<pre><code>var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();\ndlg1.Description = "Select a folder to extract to:";\ndlg1.ShowNewFolderButton = true;\ndlg1.ShowEditBox = true;\n//dlg1.NewStyle = false;\ndlg1.SelectedPath = txtExtractDirectory.Text;\ndlg1.ShowFullPathInEditBox = true;\ndlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;\n\n// Show the FolderBrowserDialog.\nDialogResult result = dlg1.ShowDialog();\nif (result == DialogResult.OK)\n{\n    txtExtractDirectory.Text = dlg1.SelectedPath;\n}\n</code></pre>\n'}, {'answer_id': 4998682, 'author': 'Ken Wayne VanderLinde', 'author_id': 616815, 'author_profile': 'https://Stackoverflow.com/users/616815', 'pm_score': 6, 'selected': False, 'text': '<p>There is the Windows API Code Pack. It\'s got a lot of shell related stuff, including the <code>CommonOpenFileDialog</code> class (in the <code>Microsoft.WindowsAPICodePack.Dialogs</code> namespace). This is the perfect solution - the usual open dialog with only folders displayed.</p>\n\n<p>Here is an example of how to use it:</p>\n\n<pre><code>CommonOpenFileDialog cofd = new CommonOpenFileDialog();\ncofd.IsFolderPicker = true;\ncofd.ShowDialog();\n</code></pre>\n\n<hr>\n\n<p>Unfortunately Microsoft no longer ships this package, but several people have unofficially uploaded binaries to NuGet. One example can be found <a href="https://www.nuget.org/packages/WindowsAPICodePack-Shell/" rel="noreferrer">here</a>. This package is just the shell-specific stuff. Should you need it, the same user has several other packages which offer more functionality present in the original package.</p>\n'}, {'answer_id': 8720922, 'author': 'Josip Medved', 'author_id': 144245, 'author_profile': 'https://Stackoverflow.com/users/144245', 'pm_score': 1, 'selected': False, 'text': '<p>On Vista you can use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb775966%28v=vs.85%29.aspx" rel="nofollow">IFileDialog</a> with FOS_PICKFOLDERS option set. That will cause display of OpenFileDialog-like window where you can select folders:</p>\n\n<pre><code>var frm = (IFileDialog)(new FileOpenDialogRCW());\nuint options;\nfrm.GetOptions(out options);\noptions |= FOS_PICKFOLDERS;\nfrm.SetOptions(options);\n\nif (frm.Show(owner.Handle) == S_OK) {\n    IShellItem shellItem;\n    frm.GetResult(out shellItem);\n    IntPtr pszString;\n    shellItem.GetDisplayName(SIGDN_FILESYSPATH, out pszString);\n    this.Folder = Marshal.PtrToStringAuto(pszString);\n}\n</code></pre>\n\n<p>For older Windows you can always resort to trick with selecting any file in folder.</p>\n\n<p>Working example that works on .NET Framework 2.0 and later can be found <a href="http://www.jmedved.com/2011/12/openfolderdialog/" rel="nofollow">here</a>.</p>\n'}, {'answer_id': 9764339, 'author': 'lantran', 'author_id': 1277704, 'author_profile': 'https://Stackoverflow.com/users/1277704', 'pm_score': 1, 'selected': False, 'text': '<p>You can use code like this</p>\n\n<p>The filter is empty string.\nThe filename is AnyName but not blank</p>\n\n<pre><code>        openFileDialog.FileName = "AnyFile";\n        openFileDialog.Filter = string.Empty;\n        openFileDialog.CheckFileExists = false;\n        openFileDialog.CheckPathExists = false;\n</code></pre>\n'}, {'answer_id': 17010931, 'author': 'Alex Essilfie', 'author_id': 117870, 'author_profile': 'https://Stackoverflow.com/users/117870', 'pm_score': 5, 'selected': False, 'text': '<p>After hours of searching I found <a href="https://stackoverflow.com/a/15456658/117870">this answer</a> by <a href="https://stackoverflow.com/users/353094/leetnightshade">leetNightShade</a> to <a href="http://www.lyquidity.com/devblog/?p=136" rel="nofollow noreferrer" title=".NET Win 7-style folder select dialog">a working solution</a>.</p>\n\n<p>There are three things I believe make this solution much better than all the others.</p>\n\n<ol>\n<li><strong>It is simple to use.</strong> \nIt only requires you include two files (which can be combined to one anyway) in your project.</li>\n<li>It falls back to the standard <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx" rel="nofollow noreferrer" title="FolderBrowserDialog Class (System.Windows.Forms)">FolderBrowserDialog</a> when used on XP or older systems.</li>\n<li>The author grants permission to use the code for any purpose you deem fit.\n\n<blockquote>\n  <p>There’s no license as such as you are free to take and do with the code what you will.</p>\n</blockquote></li>\n</ol>\n\n<p>Download the code <a href="http://www.lyquidity.com/devblog/?p=136" rel="nofollow noreferrer" title=".NET Win 7-style folder select dialog">here</a>.</p>\n'}, {'answer_id': 33836349, 'author': 'ErikE', 'author_id': 57611, 'author_profile': 'https://Stackoverflow.com/users/57611', 'pm_score': 2, 'selected': False, 'text': '<p><strong>First Solution</strong></p>\n\n<p>I developed this as a cleaned up version of <a href="http://www.lyquidity.com/devblog/?p=136" rel="nofollow noreferrer">.NET Win 7-style folder select dialog</a> by Bill Seddon of <a href="http://lyquidity.com" rel="nofollow noreferrer">lyquidity.com</a> (I have no affiliation). (I learned of his code from <a href="https://stackoverflow.com/a/17010931/57611">another answer on this page</a>). I wrote my own because his solution requires an additional Reflection class that isn\'t needed for this focused purpose, uses exception-based flow control, doesn\'t cache the results of its reflection calls. Note that the nested static <code>VistaDialog</code> class is so that its static reflection variables don\'t try to get populated if the <code>Show</code> method is never called. It falls back to the pre-Vista dialog if not in a high enough Windows version. Should work in Windows 7, 8, 9, 10 and higher (theoretically).</p>\n\n<pre><code>using System;\nusing System.Reflection;\nusing System.Windows.Forms;\n\nnamespace ErikE.Shuriken {\n    /// &lt;summary&gt;\n    /// Present the Windows Vista-style open file dialog to select a folder. Fall back for older Windows Versions\n    /// &lt;/summary&gt;\n    public class FolderSelectDialog {\n        private string _initialDirectory;\n        private string _title;\n        private string _fileName = "";\n\n        public string InitialDirectory {\n            get { return string.IsNullOrEmpty(_initialDirectory) ? Environment.CurrentDirectory : _initialDirectory; }\n            set { _initialDirectory = value; }\n        }\n        public string Title {\n            get { return _title ?? "Select a folder"; }\n            set { _title = value; }\n        }\n        public string FileName { get { return _fileName; } }\n\n        public bool Show() { return Show(IntPtr.Zero); }\n\n        /// &lt;param name="hWndOwner"&gt;Handle of the control or window to be the parent of the file dialog&lt;/param&gt;\n        /// &lt;returns&gt;true if the user clicks OK&lt;/returns&gt;\n        public bool Show(IntPtr hWndOwner) {\n            var result = Environment.OSVersion.Version.Major &gt;= 6\n                ? VistaDialog.Show(hWndOwner, InitialDirectory, Title)\n                : ShowXpDialog(hWndOwner, InitialDirectory, Title);\n            _fileName = result.FileName;\n            return result.Result;\n        }\n\n        private struct ShowDialogResult {\n            public bool Result { get; set; }\n            public string FileName { get; set; }\n        }\n\n        private static ShowDialogResult ShowXpDialog(IntPtr ownerHandle, string initialDirectory, string title) {\n            var folderBrowserDialog = new FolderBrowserDialog {\n                Description = title,\n                SelectedPath = initialDirectory,\n                ShowNewFolderButton = false\n            };\n            var dialogResult = new ShowDialogResult();\n            if (folderBrowserDialog.ShowDialog(new WindowWrapper(ownerHandle)) == DialogResult.OK) {\n                dialogResult.Result = true;\n                dialogResult.FileName = folderBrowserDialog.SelectedPath;\n            }\n            return dialogResult;\n        }\n\n        private static class VistaDialog {\n            private const string c_foldersFilter = "Folders|\\n";\n\n            private const BindingFlags c_flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;\n            private readonly static Assembly s_windowsFormsAssembly = typeof(FileDialog).Assembly;\n            private readonly static Type s_iFileDialogType = s_windowsFormsAssembly.GetType("System.Windows.Forms.FileDialogNative+IFileDialog");\n            private readonly static MethodInfo s_createVistaDialogMethodInfo = typeof(OpenFileDialog).GetMethod("CreateVistaDialog", c_flags);\n            private readonly static MethodInfo s_onBeforeVistaDialogMethodInfo = typeof(OpenFileDialog).GetMethod("OnBeforeVistaDialog", c_flags);\n            private readonly static MethodInfo s_getOptionsMethodInfo = typeof(FileDialog).GetMethod("GetOptions", c_flags);\n            private readonly static MethodInfo s_setOptionsMethodInfo = s_iFileDialogType.GetMethod("SetOptions", c_flags);\n            private readonly static uint s_fosPickFoldersBitFlag = (uint) s_windowsFormsAssembly\n                .GetType("System.Windows.Forms.FileDialogNative+FOS")\n                .GetField("FOS_PICKFOLDERS")\n                .GetValue(null);\n            private readonly static ConstructorInfo s_vistaDialogEventsConstructorInfo = s_windowsFormsAssembly\n                .GetType("System.Windows.Forms.FileDialog+VistaDialogEvents")\n                .GetConstructor(c_flags, null, new[] { typeof(FileDialog) }, null);\n            private readonly static MethodInfo s_adviseMethodInfo = s_iFileDialogType.GetMethod("Advise");\n            private readonly static MethodInfo s_unAdviseMethodInfo = s_iFileDialogType.GetMethod("Unadvise");\n            private readonly static MethodInfo s_showMethodInfo = s_iFileDialogType.GetMethod("Show");\n\n            public static ShowDialogResult Show(IntPtr ownerHandle, string initialDirectory, string title) {\n                var openFileDialog = new OpenFileDialog {\n                    AddExtension = false,\n                    CheckFileExists = false,\n                    DereferenceLinks = true,\n                    Filter = c_foldersFilter,\n                    InitialDirectory = initialDirectory,\n                    Multiselect = false,\n                    Title = title\n                };\n\n                var iFileDialog = s_createVistaDialogMethodInfo.Invoke(openFileDialog, new object[] { });\n                s_onBeforeVistaDialogMethodInfo.Invoke(openFileDialog, new[] { iFileDialog });\n                s_setOptionsMethodInfo.Invoke(iFileDialog, new object[] { (uint) s_getOptionsMethodInfo.Invoke(openFileDialog, new object[] { }) | s_fosPickFoldersBitFlag });\n                var adviseParametersWithOutputConnectionToken = new[] { s_vistaDialogEventsConstructorInfo.Invoke(new object[] { openFileDialog }), 0U };\n                s_adviseMethodInfo.Invoke(iFileDialog, adviseParametersWithOutputConnectionToken);\n\n                try {\n                    int retVal = (int) s_showMethodInfo.Invoke(iFileDialog, new object[] { ownerHandle });\n                    return new ShowDialogResult {\n                        Result = retVal == 0,\n                        FileName = openFileDialog.FileName\n                    };\n                }\n                finally {\n                    s_unAdviseMethodInfo.Invoke(iFileDialog, new[] { adviseParametersWithOutputConnectionToken[1] });\n                }\n            }\n        }\n\n        // Wrap an IWin32Window around an IntPtr\n        private class WindowWrapper : IWin32Window {\n            private readonly IntPtr _handle;\n            public WindowWrapper(IntPtr handle) { _handle = handle; }\n            public IntPtr Handle { get { return _handle; } }\n        }\n    }\n}\n</code></pre>\n\n<p>It is used like so in a Windows Form:</p>\n\n<pre><code>var dialog = new FolderSelectDialog {\n    InitialDirectory = musicFolderTextBox.Text,\n    Title = "Select a folder to import music from"\n};\nif (dialog.Show(Handle)) {\n    musicFolderTextBox.Text = dialog.FileName;\n}\n</code></pre>\n\n<p>You can of course play around with its options and what properties it exposes. For example, it allows multiselect in the Vista-style dialog.</p>\n\n<p><strong>Second Solution</strong></p>\n\n<p><a href="https://stackoverflow.com/a/15386992/57611">Simon Mourier gave an answer</a> that shows how to do the exact same job using interop against the Windows API directly, though his version would have to be supplemented to use the older style dialog if in an older version of Windows. Unfortunately, I hadn\'t found his post yet when I worked up my solution. Name your poison!</p>\n'}, {'answer_id': 46712973, 'author': 'AltF4_', 'author_id': 1073481, 'author_profile': 'https://Stackoverflow.com/users/1073481', 'pm_score': -1, 'selected': False, 'text': '<p>I know the question was on configuration of <code>OpenFileDialog</code> but seeing that Google brought me here i may as well point out that if you are ONLY looking for folders you should be using a <code>FolderBrowserDialog</code> Instead as answered by another SO question below</p>\n\n<p><a href="https://stackoverflow.com/questions/11465237/how-to-specify-path-using-open-file-dialog-in-vb-net">How to specify path using open file dialog in vb.net?</a></p>\n'}, {'answer_id': 52638564, 'author': 'C. Augusto Proiete', 'author_id': 211672, 'author_profile': 'https://Stackoverflow.com/users/211672', 'pm_score': 1, 'selected': False, 'text': '<p>The <strong><a href="https://github.com/augustoproiete/ookii-dialogs-wpf" rel="nofollow noreferrer">Ookii Dialogs for WPF</a></strong> library has a class that provides an implementation of a folder browser dialog for WPF.</p>\n<blockquote>\n<p><a href="https://github.com/augustoproiete/ookii-dialogs-wpf" rel="nofollow noreferrer">https://github.com/augustoproiete/ookii-dialogs-wpf</a></p>\n</blockquote>\n<p><a href="https://github.com/augustoproiete/ookii-dialogs-wpf" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IUz1P.png" alt="Ookii Folder Browser Dialog" /></a></p>\n<p>There\'s also a version that works with <a href="https://github.com/augustoproiete/ookii-dialogs-winforms" rel="nofollow noreferrer">Windows Forms</a>.</p>\n'}]
['https://Stackoverflow.com/questions/31059', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2547/']