Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows 7

Using the Windows 7 Libraries : USING THE EXPLORER BROWSER CONTROL (part 2)

7/30/2014 9:06:26 PM

3. Writing the Explorer Browser Example Code

The Explorer Browser example doesn't contain a lot of code, yet you can do quite a bit with it because the ExplorerBrowser control provides a lot of functionality by itself. When you start this example, you can choose any of the KnownFolder entries and see where this takes you in the right Browser pane. Listing 1 shows the code needed for this example.

Example 1. Using the Explorer Browser control to create an interesting interface
public frmMain()
{
// Perform the standard initialization.
InitializeComponent();

// Initialize the folder list.
foreach (IKnownFolder Folder in KnownFolders.All)
lstFolders.Items.Add(Folder.CanonicalName);

// Choose an initial folder.
lstFolders.SelectedItem = KnownFolders.Documents.CanonicalName;
Browser.Navigate(ShellFileSystemFolder.FromFolderPath(
KnownFolders.Documents.Path));
}

private void lstFolders_SelectedIndexChanged(object sender, EventArgs e)
{
try
{

// Locate the selection.
foreach (IKnownFolder Folder in KnownFolders.All)

// Compare the folder name to the selected name.
if (Folder.CanonicalName == lstFolders.Text)
{

// Change the selected folder.
Browser.Navigate(
ShellFileSystemFolder.FromFolderPath(
Folder.Path));

// Exit the loop.
break;
}
}
catch
{
// Display an error message.
MessageBox.Show("Can't select the specified item.");
}
}

The code begins with the frmMain() constructor. The example performs the standard initialization. It then fills lstFolders with the names of all the KnownFolder entries using a foreach loop. The CanonicalName property provides the most readable entries. The ComboBox control automatically sorts the names for you.

It's also important to provide an initial selection. The example uses the KnownFolders.Documents entry for this purpose. Setting lstFolders means changing the SelectedItem property to the appropriate CanonicalName value. To set the Browser display, the code relies on the Navigate() method. You must provide a ShellFileSystemFolder or a ShellFile object in most cases (any appropriate ShellObject should work). The example uses the ShellFileSystemFolder.FromFolderPath() method to obtain the appropriate value. In this case, the value is from KnownFolders.Documents.Path. At this point, the application presents an initial display similar to the one shown in Figure 3.

After the user makes a selection, the example calls lstFolders_SelectedIndexChanged(). The lstFolders.Items collection contains a list of canonical names, not paths. The first task the code performs is to match the canonical name in an IKnownFolder object, Folder, with the canonical name the user has selected. When the two CanonicalName property values match, the code extracts a path from Folder. It then calls Browser.Navigate() to set the Browser display.

Figure 3. The initial display shows the user's personal folders.


Other -----------------
- Using the Windows 7 Libraries : CONSIDERING USER-DEFINED COLLECTIONS
- Using the Windows 7 Libraries : USING NON-FILESYSTEM CONTAINERS
- Using the Windows 7 Libraries : WORKING WITH KNOWN FOLDERS
- Conducting Research in OneNote 2010 : Translating Text
- Conducting Research in OneNote 2010 : Researching a Topic, Customizing the Research Task Pane
- Conducting Research in OneNote 2010 : Handling the Research Task Pane
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Macro Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting ActiveX Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Add-in Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Document Related Security Options
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro