这是我在单击“保存”按钮时的代码:
OpenFileDialog myOpenfileDialog = new OpenFileDialog();
myOpenfileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
myOpenfileDialog.FilterIndex = 2;
myOpenfileDialog.RestoreDirectory = true;
if (myOpenfileDialog.ShowDialog() == DialogResult.OK)
{
FileUploadData.SaveAs(myOpenfileDialog.FileName);//my file upload control taking the path to save the file to the selected location
} 我得到了一个例外:
在进行OLE调用之前,必须将
当前线程设置为单线程单元(STA)模式。确保主函数上标记了STAThreadAttribute。只有当调试器附加到进程时,才会引发此异常。这是threadStateException
发布于 2010-11-15 07:42:51
嗯,这个消息在我看来相当清楚--你需要使用STA线程。如果要编写Windows应用程序,可以确保Main方法使用如下属性进行修饰:
[STAThread]
static void Main(string[] args)
{
...
}如果您正在编写ASP.NET应用程序,那么您不应该首先在代码中使用Windows控件。我之所以提到这一点,是因为您已经用winforms和asp.net标记了您的问题--您不应该将这两个问题的代码混合在一起。
https://stackoverflow.com/questions/4182349
复制相似问题