Microsoft KB Archive/818459

= FolderBrowserDialog.RootFolder displays desktop folders when you set it to non-desktop values =

Article ID: 818459

Article Last Modified on 11/26/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Windows 98 Standard Edition
 * Microsoft Windows NT 4.0

-



SYMPTOMS
You create a FolderBrowserDialog control on a Windows form, and you set the RootFolder property to one of the following values:
 * CommonApplicationData
 * CommonProgramFiles
 * Cookies
 * History
 * InternetCache
 * LocalApplicationData
 * LocalApplicationData
 * MyPictures
 * ProgramFiles
 * System

When you run the application on a computer that is running the Microsoft Windows 98 operating system or the Microsoft Windows NT 4.0 operating system, a Browse For Folder dialog box is displayed with the folders on the desktop, instead of displaying the folders in the selected RootFolder.



CAUSE
This is a limitation of the BrowseForFolder method on the Windows 98 operating system and the Windows NT 4.0 operating system.

Note The BrowseForFolder method creates the BrowseForFolder dialog box. This dialog box allows the user to select a folder.



STATUS
This behavior is by design.



MORE INFORMATION
The Microsoft Visual Studio .NET or Visual Studio 2005 IDE will only run on computers that are running the Windows 2000 operating system or a later version. Therefore, it is a good idea to build the sample application on a computer that is running the Windows 2000 operating system or a later version. Install Microsoft .NET Framework 1.1 on a computer that is running the Windows 98 operating system, and then copy the executable file that you built on a computer that runs the Windows 2000 operating system or a later version.

Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET (2003) or in Microsoft Visual Studio 2005, create a new Windows application by using Visual Basic 2005, Microsoft Visual Basic .NET, or Microsoft Visual C#.

By default, Form1 is created. From the toolbox, drag a FolderBrowserDialog control to Form1. Right-click FolderBrowserDialog1, and then click Properties. In the Properties window, set the RootFolder property to ProgramFiles. From the toolbox, drag a Button control to Form1.  Add the following code to the Click event of Button1.

Visual Basic .NET or Visual Basic 2005 Code ' Displays a dialog box that allows the user to select a folder. FolderBrowserDialog1.ShowDialog Visual C# .NET Code //Displays a dialog box that allows the user to select a folder. folderBrowserDialog1.ShowDialog; </li> From the toolbox, drag a Button control to Form1.</li>  Add the following code to the Click event of Button2.

Visual Basic .NET or Visual Basic 2005 Code ' Displays the path of program files folder in your local computer. MsgBox(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)) Visual C# .NET Code //Displays the path of program files folder in your local computer. MessageBox.Show(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); </li> On the Build menu, click Build Solution.</li> Locate WindowsApplication1.exe under the Bin subfolder of the WindowsApplication1 project.</li> Copy WindowsApplication1.exe to the computer that is running the Windows 98 operating system.</li> Right-click WindowsApplication1.exe, and then click Open.</li> Click Button1.

The folders on the desktop are displayed in Browse For Folder.</li> Click Button2.

You receive a message box with the path of the Program Files folder.</li></ol>

<div class="references_section">