The Haunted House

Sunday, July 01, 2007

Vista File Dialogs

Recently I upgraded my laptop to run the new Windows Vista Ultimate Edition so that I would play around with some of the new technologies for work. I thought it would be fun to play around with the new Windows Presentation Foundation.

As I was creating a small application I wanted to bring up an open file dialog box. But guess what, Microsoft has moved this to a different namespace. The normal file dialog box can be found in the Microsoft.Win32 namespace. Ok, this isn't to bad, I can live with that. I fired up the open file dialog box with the following code:


OpenFileDialog openFile = new OpenFileDialog();
openFile.Title = "Open a lotter file.";
openFile.ShowDialog();


Up popped the dialog box as shown below. The only problem is, I am using Vista, so I want to use the new latest greatest snazzy graphical dialog box, not the old XP clunky grey dialog.


By default the Vista common dialogs are not included with .NET3, but you can use them. First you must download the Microsoft Windows SDK for Vista. Once you have done this browse in explorer too :

C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples

Load up the Vista Bridge solution file and build it. Then copy the assemblies to your solution and include them as references.

The common dialog boxes are in the following namespace:

using Microsoft.SDK.Samples.VistaBridge.Library;

You can access the file dialog boxes like follows:



CommonOpenFileDialog openDialog = new CommonOpenFileDialog();
openDialog.Title = "Open a lotter file.";
openDialog.Multiselect = true;
CommonFileDialogResult result = openDialog.ShowDialog();



CommonSaveFileDialog saveDialog = new CommonSaveFileDialog();
saveDialog.Title = "Open a lotter file.";
CommonFileDialogResult result = saveDialog.ShowDialog();


There are lots of other common vista dialog boxes in this library but I havn't had a chance to try them out yet.

0 Comments:

Post a Comment

<< Home