简体   繁体   中英

question about c# asp.net

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM