Error while using OpenFileDialog(). <<URGENT>> RRS feed

  • Question

  • Hi,


    I am having an aspx page from which, on a button click an open file dialog should open up from which i can select a file.

    i wrote the following code on the button's click event.

    OpenFileDialog _filedialog = new OpenFileDialog();

                _filedialog.InitialDirectory = @"C:\";
                _filedialog.Title = "Add Preview Image";
                _filedialog.Filter = "Image files|*.jpeg;*.jpg;*.bmp;*.png";
                _filedialog.RestoreDirectory = true;
                if (_filedialog.ShowDialog() == DialogResult.OK)
                    txtPromoPreviewImagePath.Text = _filedialog.FileName;


    Now, when i run the project and click the button, hoping to see the open dialog file browser window, i see this 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.


    Thanks, Manu



    • Moved by SamAgain Tuesday, November 9, 2010 9:41 AM not 64bit .net question (From:64-Bit .NET Framework Development.)
    Wednesday, October 27, 2010 1:27 PM


  • Hello,

               Thank you for your post!  I would suggest creating a new thread for your question in the ASP forums  located here:  http://forums.asp.net

               Thanks & Regard!

    Shivendra Pratap Singh Tier 2 Application Support Server and Tools Online Operations Team
    Friday, November 19, 2010 5:45 PM