Reputation: 9
in order to use the FolderBrowserDialog control in asp.net, i had to add a reference to System.Windows.Forms in my project.
i wrote this code:
FolderBrowserDialog f = new FolderBrowserDialog();
f.ShowDialog();
but this error occured:
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.
any help?
Upvotes: 0
Views: 177
Reputation: 9599
You cannot use Windows Forms controls in ASP.NET. And in fact using the FolderBrowserDialog from ASP.NET doesn't make a lot of sense, since it is a webpage. Web applications can't get direct access to a user's filesystem. If you want to get a file from the user you should use a FileUpload control.
Upvotes: 1
Reputation: 245389
If you're trying to use this control in an ASP.NET application, you're going to be sadly disappointed.
You can't use WinForms controls on ASP.NET Pages. You should check out the FileUpload control instead (it will allow your users to pick a file and upload it to the site).
If you're actually building a WinForms application (not ASP.NET), then the fix is quite easy (and you should fix your question and tagging):
public static void Main()
Becomes:
[STAThread]
public static void Main()
Keep in mind though, Visual Studio usually adds this to your generated code when you create a WinForms project.
Upvotes: 1