Hi, I have a problem with a FolderBrowserDialog.
I use VS2003, C# language on a Windows 2003 System and I ran the test project from an Administrator user.
So, I tried to specify a path to a folder using the FolderBrowserDialog.
However, if I browse to the current user Desktop and press "MakeFolder", an exception occurs:
System.Runtime.InteropServices.SEHException: External component has thrown an exception.
at System.Windows.Forms.Shell32.SHBrowseForFolder(BROWSEINFO lpbi)
at System.Windows.Forms.FolderBrowserDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at TestFolderBrowserDialog.Form1.btnBrowse_Click(Object sender, EventArgs e) in
The folder is created but the FolderBrowserDialog throws this exception, so the application crashes.
The test application is a simple windows form with a browse button.
Do you know what could I do to avoid this exception

FolderBrowserDialog Exception when creating folder on Desktop
Robert Wang
Now it seems it works....
Before yesterday when I noticed the exception some things have changed.
Yesterday, I noticed some strange behaviour with Internet Explorer 7 Beta. I had an instance of IE open, but when switching from one tab page to another, the whole screen was refreshing, not only the currently viewed tab page.
For today, I upgraded to IE7, release version and I also installed some updates for Windows2003 and I 've also restarted the PC and the exception does no longer occur when I try to make a folder on the desktop. With the latest IE7, I didn't notice any screen refreshing when changing from one tab to another
I don't have other clues...
preed_lahey
It might be a bug in v1.x of the framework. It works under v2.0. Can you post the code you're using so we can test it.
Michael Taylor - 11/3/06
Matt DC
It's not a complicated application. It's just a test form with 2 textboxes, a button and a FolderBrowserButton object. In the handler of the OnClick event, I show the FolderBrowserDialog. In the FolderBrowserDialog I go in the Desktop folder of the current user and I try to make a new folder...but an exception is thrown.
Below is the code(a simple test form):
using
System;using System.Drawing;
using
System.Collections;using
System.ComponentModel;using
System.Windows.Forms;using
System.Data;namespace
TestFolderBrowserDialog{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
private System.Windows.Forms.Button btnBrowse;
private System.Windows.Forms.Label lblPath;
private System.Windows.Forms.TextBox txtBxPath;
private System.Windows.Forms.TextBox txtBxStackTrace;
private System.Windows.Forms.Label lblStackTrace;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region
Windows Form Designer generated code/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.btnBrowse = new System.Windows.Forms.Button();
this.txtBxPath = new System.Windows.Forms.TextBox();
this.lblPath = new System.Windows.Forms.Label();
this.txtBxStackTrace = new System.Windows.Forms.TextBox();
this.lblStackTrace = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnBrowse
//
this.btnBrowse.Location = new System.Drawing.Point(352, 64);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Size = new System.Drawing.Size(24, 23);
this.btnBrowse.TabIndex = 0;
this.btnBrowse.Text = "...";
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
//
// txtBxPath
//
this.txtBxPath.Location = new System.Drawing.Point(48, 64);
this.txtBxPath.Name = "txtBxPath";
this.txtBxPath.Size = new System.Drawing.Size(304, 20);
this.txtBxPath.TabIndex = 1;
this.txtBxPath.Text = "";
//
// lblPath
//
this.lblPath.Location = new System.Drawing.Point(8, 64);
this.lblPath.Name = "lblPath";
this.lblPath.Size = new System.Drawing.Size(40, 23);
this.lblPath.TabIndex = 2;
this.lblPath.Text = "Path:";
//
// txtBxStackTrace
//
this.txtBxStackTrace.Location = new System.Drawing.Point(8, 136);
this.txtBxStackTrace.Multiline = true;
this.txtBxStackTrace.Name = "txtBxStackTrace";
this.txtBxStackTrace.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtBxStackTrace.Size = new System.Drawing.Size(552, 104);
this.txtBxStackTrace.TabIndex = 3;
this.txtBxStackTrace.Text = "";
//
// lblStackTrace
//
this.lblStackTrace.Location = new System.Drawing.Point(8, 112);
this.lblStackTrace.Name = "lblStackTrace";
this.lblStackTrace.Size = new System.Drawing.Size(100, 16);
this.lblStackTrace.TabIndex = 4;
this.lblStackTrace.Text = "StackTrace:";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(568, 261);
this.Controls.Add(this.lblStackTrace);
this.Controls.Add(this.txtBxStackTrace);
this.Controls.Add(this.lblPath);
this.Controls.Add(this.txtBxPath);
this.Controls.Add(this.btnBrowse);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnBrowse_Click(object sender, System.EventArgs e)
{
try
{
if(folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
txtBxPath.Text = folderBrowserDialog.SelectedPath;
}
}
catch(Exception ex)
{
txtBxStackTrace.Text = ex.ToString();
MessageBox.Show(ex.ToString());
}
}
}
}
D-S
Your code is working for me. I've tried a couple of different combinations. Do you select the Desktop item or do you borrow down to the Document and Settings/... folder and then create the folder Both cases work for me but there is a UI glitch when searching for the actual folder. Again it might be a v1.x issue. I don't have VS2003 so I can't test it. It does work in v2.0.
Michael Taylor - 11/7/06