簡體   English   中英

關於C#asp.net的問題

[英]question about c# asp.net

為了在asp.net中使用FolderBrowserDialog控件,我必須在項目中添加對System.Windows.Forms的引用。

我寫了這段代碼:

 FolderBrowserDialog f = new FolderBrowserDialog();  
 f.ShowDialog();  

但發生此錯誤:

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.  

任何幫助?

如果您試圖在ASP.NET應用程序中使用此控件,您將很失望。

您不能在ASP.NET頁上使用WinForms控件。 您應該改為檢出FileUpload控件(它將允許您的用戶選擇一個文件並將其上傳到站點)。

如果您實際上是在構建WinForms應用程序(而不是ASP.NET) ,則此修復非常簡單(並且您應該修復問題和標記):

public static void Main()

變為:

[STAThread]
public static void Main()

但是請記住,Visual Studio通常在創建WinForms項目時將其添加到生成的代碼中。

您不能在ASP.NET中使用Windows窗體控件。 實際上,從ASP.NET使用FolderBrowserDialog並沒有多大意義,因為它是一個網頁。 Web應用程序無法直接訪問用戶的文件系統。 如果要從用戶獲取文件,則應使用FileUpload控件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM