Rectangle 27 0

Here is a custom UITypeEditor that allows you to use the Vista Folder Browser:

You can use it like any other editor:

[EditorAttribute(typeof(FolderNameEditor2), typeof(System.Drawing.Design.UITypeEditor))]

It relies on a custom FolderBrowser2 class that I have written for the occasion. Of course, this will work only on Windows Vista and higher. On previous Windows version, there is no other folder browser than the simple one.

public class FolderNameEditor2 : UITypeEditor
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        return UITypeEditorEditStyle.Modal;

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        FolderBrowser2 browser = new FolderBrowser2();
        if (value != null)
            browser.DirectoryPath = string.Format("{0}", value);

        if (browser.ShowDialog(null) == DialogResult.OK)
            return browser.DirectoryPath;

        return value;

public class FolderBrowser2
    public string DirectoryPath { get; set; }

    public DialogResult ShowDialog(IWin32Window owner)
        IntPtr hwndOwner = owner != null ? owner.Handle : GetActiveWindow();

        IFileOpenDialog dialog = (IFileOpenDialog)new FileOpenDialog();
            IShellItem item;
            if (!string.IsNullOrEmpty(DirectoryPath))
                IntPtr idl;
                uint atts = 0;
                if (SHILCreateFromPath(DirectoryPath, out idl, ref atts) == 0)
                    if (SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out item) == 0)
            uint hr = dialog.Show(hwndOwner);
            if (hr == ERROR_CANCELLED)
                return DialogResult.Cancel;

            if (hr != 0)
                return DialogResult.Abort;

            dialog.GetResult(out item);
            string path;
            item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
            DirectoryPath = path;
            return DialogResult.OK;

    private static extern int SHILCreateFromPath([MarshalAs(UnmanagedType.LPWStr)] string pszPath, out IntPtr ppIdl, ref uint rgflnOut);

    private static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);

    private static extern IntPtr GetActiveWindow();

    private const uint ERROR_CANCELLED = 0x800704C7;

    private class FileOpenDialog

    private interface IFileOpenDialog
        uint Show([In] IntPtr parent); // IModalWindow
        void SetFileTypes();  // not fully defined
        void SetFileTypeIndex([In] uint iFileType);
        void GetFileTypeIndex(out uint piFileType);
        void Advise(); // not fully defined
        void Unadvise();
        void SetOptions([In] FOS fos);
        void GetOptions(out FOS pfos);
        void SetDefaultFolder(IShellItem psi);
        void SetFolder(IShellItem psi);
        void GetFolder(out IShellItem ppsi);
        void GetCurrentSelection(out IShellItem ppsi);
        void SetFileName([In, MarshalAs(UnmanagedType.LPWStr)] string pszName);
        void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
        void SetTitle([In, MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
        void SetOkButtonLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszText);
        void SetFileNameLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
        void GetResult(out IShellItem ppsi);
        void AddPlace(IShellItem psi, int alignment);
        void SetDefaultExtension([In, MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
        void Close(int hr);
        void SetClientGuid();  // not fully defined
        void ClearClientData();
        void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);
        void GetResults([MarshalAs(UnmanagedType.Interface)] out IntPtr ppenum); // not fully defined
        void GetSelectedItems([MarshalAs(UnmanagedType.Interface)] out IntPtr ppsai); // not fully defined

    private interface IShellItem
        void BindToHandler(); // not fully defined
        void GetParent(); // not fully defined
        void GetDisplayName([In] SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
        void GetAttributes();  // not fully defined
        void Compare();  // not fully defined

    private enum SIGDN : uint
        SIGDN_FILESYSPATH = 0x80058000,
        SIGDN_PARENTRELATIVE = 0x80080001,
        SIGDN_URL = 0x80068000

    private enum FOS
        FOS_CREATEPROMPT = 0x2000,
        FOS_DEFAULTNOMINIMODE = 0x20000000,
        FOS_DONTADDTORECENT = 0x2000000,
        FOS_FILEMUSTEXIST = 0x1000,
        FOS_FORCESHOWHIDDEN = 0x10000000,
        FOS_HIDEMRUPLACES = 0x20000,
        FOS_HIDEPINNEDPLACES = 0x40000,
        FOS_NOCHANGEDIR = 8,
        FOS_NODEREFERENCELINKS = 0x100000,
        FOS_NOREADONLYRETURN = 0x8000,
        FOS_NOTESTFILECREATE = 0x10000,
        FOS_NOVALIDATE = 0x100,
        FOS_PATHMUSTEXIST = 0x800,
        FOS_PICKFOLDERS = 0x20,
        FOS_SHAREAWARE = 0x4000,

Holy crap, this is just what I needed for a project I'm working on, and it's been REALLY hard to find. I'm mercilessly stealing a tweaked version of this to permanently go in my code snippet repertoire. Thanks! One quick suggestion: You might want to add code to make it degrade gracefully to a FolderBrowserDialog if the Vista-style dialog isn't available.

c# - Show detailed Folder Browser from a PropertyGrid - Stack Overflow

c# propertygrid folderbrowserdialog
Rectangle 27 0

It's not as easy as it seems to implement a control like that. Explorer works with shell items, not filesystem items (ex: the control panel, the printers folder, and so on). If you need to implement it i suggest to have a look at the Windows shell functions at

"It's not as easy as it seems to implement a control like that." I realize that. Which is exactly why I would prefer not to reinvent the wheel.

c# - How to create an Explorer-like folder browser control? - Stack Ov...

c# .net winforms explorer
Rectangle 27 0

The code that you are using is for windows forms, so it will not work in a web project. This is what the error messages are telling you.

If you want the user to select a directory on the WEB server machine, then you will need to gather the list of folders that they can select from and present them to them in a Tree or other user interface construct that makes sense for the task you wish to perform.

I was hoping to only have the user select a folder on their local machine, without having to select a file.

Ah, I see your issue. This is unfortunately not available in straight HTML and, even if you managed to figure it out, you wouldn't be able to do anything with the files in that path due to security concerns. If you know the user base (i.e. it's not a general type of application), you could re-use your current form implementation in a ClickOnce app. Alternatively, you could create a silverlight applet loosely based on your current code.

windows - opening a local folder browser from web browser - Stack Over...

Rectangle 27 0

I found that I could only start multiple html files in the same window if I called them in the same command, perhaps this will work for you -

The file:// was unnecessary for me.

I didn't test it, It's probably to do with my setting of the files variable. I will fiddle with it later. However, I know that at least Chrome can open multiple files in the same window like so: start Chrome test.html test1.html.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

internet explorer - How do I Open all html files in a folder in multip...

html internet-explorer batch-file
Rectangle 27 0

There is no concept of folder selection in the HTML/JavaScript platform. Even if you could select one, you wouldn't be able to do anything with the folder path. If you use a plugin technology like Silverlight, Flash, or a Java applet, they may have folder selection and reading capabilities.

Well, I am not sure that is true. Here is another solution that I have recently found. and Microsoft has one in the MSDN I'm just trying to get fixed what I have on the server without having to re-code much.

That first link would be helpful if you want to access the folder structure of the web server on the server, not the client; web applications do not have access to a client's file system. The second link is for Windows forms; not all WinForms controls have WebForms equivalents.

My problem exactly. But your telling me other than the FileUpload control, there is no way to see the local folder path from a web bowser? And why does it work on my DEV PC, regardless of the fact that web server and local PC are one in the same, the environment is still a web browser, right?

Even if you managed to get the folder path, you couldn't do anything with it.

Then I guess I am at a loss as to why this works on my DEV PC. I process hundreds of files within the choosen directory with no problem, writing data into an Access table from a gridview displayed on the web page.

windows - opening a local folder browser from web browser - Stack Over...

Rectangle 27 0

You might be taking the wrong approach here - have you considered using an ordinary ListView control? You'll have much more control over how your icons, columns, etc., are shown.

MSDN even has a tutorial showing how to use a ListView to mimic Explorer functionality.

browser - Folder Explorer in C# - Stack Overflow

c# browser folder explorer
Rectangle 27 0

You can simply add an empty index.html. This will stop the direct access to that folder.

Options -Indexes

Enter the above code into htaccess. That will produce a 403 HTTP Status code on folder access, but will allow you do share the content !

php - How do i restrict direct access (from browser) to a folder but a...

php .htaccess
Rectangle 27 0

Turn indexes off in the options.

Options -Indexes

php - How do i restrict direct access (from browser) to a folder but a...

php .htaccess
Rectangle 27 0

The following code snippet gives the dialog theme you want:

Dim dialog As New Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog()    
dialog.IsFolderPicker = True
dialog.ShowDialog() - HOW - Detailed Folder Browser - VS 2010 - Stack Overflow
Rectangle 27 0

1) I don't quite understand your requirements in the first question. Please add some more details or may be an image of the required layout.

2) To host a Win Forms control in WPF, try following article on MSDN:

@decyclone-Thanks for the info actually I am just going through some questions and found a part of my first question I asked and it was just to display a folder dialog and here I have got some answer for that and after selecting bulk images from that folder I need to display all the Images on a control as In winforms we can use flow layout panel or list view .So I would like to know in wpf which control do I need use to display those Images?

@Kiran: It is very easy to do that in WPF. Use and ItemsControl with a custom ItemTemplate.

Display multiple images using folder browser dialog in WPF and how to ...

wpf image dialog folder user-controls