Is it possible to embed the Windows Explorer file/folder browser view in a WPF or a WinForms window?
I basically want to host the file/folder browser as part of my a
As far as I know, there isn't any File/Folder browser control out of the box in Windows Forms nor WPF.
However there are commercial third-party controls that offer a Windows Explorer-like interface to browse files and folders on disk. Take a look at these products from LogicNP:
Alternatively, you could host the Windows Forms WebBrowser control in WPF and use it to browse the filesystem, since it is integrated with the Windows shell.
In XAML you could do something like this:
<Window x:Class="Samples.FilesystemBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="Filesystem Browser">
<StackPanel>
<WindowsFormsHost>
<wf:WebBrowser Url="C:\" />
</WindowsFormsHost>
</StackPanel>
</Window>
Note, that with .NET 3.5 SP1 Microsoft added a native WPF WebBrowser control, so you can optionally use that instead:
<Window x:Class="Samples.FilesystemBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Filesystem Browser">
<StackPanel>
<WebBrowser Source="C:\" />
</StackPanel>
</Window>
The approach in my answer isn't one I would necessarily recommend, as it is basically a huge hack. However, it is possible to 'host' pretty much any Windows application inside another. Caveats:
The basic approach would be to:
You'll want Spy++ in order to figure out what messages happen when.
Yes, this is a great way to build lots of very ugly and fragile code, but it's (a) sometimes the only way to get things working right; and (b) great for learning what's going on under the hood of Windows.Forms / MFC / etc.
Windows Vista’s Shell introduced a new control which implements the IExplorerBrowser interface; this is the recommended method of hosting a Windows Shell filesystem view within your application. Developers building applications using .NET can use the wrapped version of the ExplorerBrowser control available in the Windows API CodePack for .NET.
Please note that this interface is only available on Windows Vista and later. If your application needs to run on earlier Windows versions, you will need to fallback to the old WebOC implementation on those platforms.
http://msdn.microsoft.com/en-us/library/bb761909(VS.85).aspx http://code.msdn.microsoft.com/WindowsAPICodePack
This is recommended over hosting the web browser control due to a Win7 issue described here: http://blogs.msdn.com/ieinternals/archive/2009/12/30/Windows-7-Web-Browser-Control-will-not-browse-file-system.aspx
I've written an open-source library for embedding windows explorer in .NET applications. You can take a look at http://gong-shell.sourceforge.net/
It exposes WinForms controls, as well as providing a .NET language interface to the Windows Shell. It's licenced under the GPL, so using it in a similarly licensed application is free, however if you want to use it in a commercial application drop me an email and I'm sure we can work something out!