|
In a click event in asp.net, I use the following code:
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog ();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (* .txt) | * .txt | All files (*. *) | *. *";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog () == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile ())! = null)
{
// Insert code to read the stream here.
myStream.Close ();
}
}
This error is reported in openFileDialog1.ShowDialog ():
Before you can call OLE, you must set the current thread to single-threaded apartment (STA) mode. Make sure your Main function is tagged with STAThreadAttribute. This exception is only thrown by attaching a debugger to the process. |
|