Hi
I am trying to add FolderBrowserDialog to my ASP.NET page. So i added a reference to using System.Windows.Forms. Now i have placed a button and in button click event i have written code like this .

protected void Button1_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog fbd = new FolderBrowserDialog();
        fbd.ShowDialog();
    }

When i run the application and click on the button i am geeting the following error.

Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.

pls some help me to solve this problem

Do as the error says - apply the STAThread attribute to your Main method.

-G Himangi, LogicNP Software [url]http://www.ssware.com[/url] 
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs rapidly in .Net & MFC/ATL/C++

Hi
I am trying to add FolderBrowserDialog to my ASP.NET page. So i added a reference to using System.Windows.Forms. Now i have placed a button and in button click event i have written code like this .

protected void Button1_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog fbd = new FolderBrowserDialog();
        fbd.ShowDialog();
    }

When i run the application and click on the button i am geeting the following error.

Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.

pls some help me to solve this problem

Edited 3 Years Ago by mike_2000_17: Fixed formatting

As I know, FolderBrowserDialog only runs in Windows Desktop not in ASP.NET.
You may use third-party control.

This article has been dead for over six months. Start a new discussion instead.