We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

HOWTO: Start FolderBrowser in a non-special folder

The FolderBrowser control can only be started in one of the predefined "special" folders. I wanted it to start in the current folder. Here is an example of how to do that: First, add a FolderBrowserCallback event handler to the FolderBrowser object. Then add the following code specifying the directory you want the folder to open: using System.Runtime.InteropServices; /*...*/ [DllImport("user32.dll",CharSet=CharSet.Unicode)] public static extern UInt32 SendMessage( IntPtr hWnd, UInt32 Msg, UInt32 wParam, IntPtr lParam); private void folderBrowser1_FolderBrowserCallback(object sender, Syncfusion.Windows.Forms.FolderBrowserCallbackEventArgs e) { if (e.FolderBrowserMessage==FolderBrowserMessage.Initialized) { const int BFFM_SETSELECTIONW=1127; SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,Marshal.StringToHGlobalUni(@"c:\temp")); } }

5 Replies

ED Eric Duesing August 8, 2003 10:14 AM UTC

Actually, that leaks, doesn't it. Instead of this: >SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,Marshal.StringToHGlobalUni(@"c:\temp")); Try This: IntPtr p=Marshal.StringToHGlobalUni(@"c:\temp"); SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,p); Marshal.FreeHGlobal(p);


RP Ramesh Praveen Syncfusion Team August 11, 2003 12:21 PM UTC

Eric, Thanks for the info! That's a big help, it's been a frequent feature request. We will log this in our KB. -Praveen


ME Mark Emerson August 26, 2003 09:43 PM UTC

Eric, Thank you! I've been wanting the ability to set a start location in the .NET world for sometime and hated using the old VB6 controls within wrappers. Excellent! Mark


MS Martin Schacher October 11, 2005 03:52 PM UTC

Is there a workaround for vb to set the initial-directory? >Eric, > >Thank you! I''ve been wanting the ability to set a start location in the .NET world for sometime and hated using the old VB6 controls within wrappers. Excellent! > >Mark


AR Anupama Roy Syncfusion Team October 13, 2005 08:57 AM UTC

Hi Martin, The following features for FolderBrowser have been added to our build internally. 1) Enumeration value FolderBrowserFolder.CustomStartLocation for Folder.StartLocation property. 2) FolderBrowserFolder.CustomStartLocation property for dialog root path. 3) FolderBrowserFolder.SelectLocation property for automatic scroll and highlight of desired path. Which version of Syncfusion are you using now? Best Regards, Anu.

Loader.
Live Chat Icon For mobile
Up arrow icon