G
Guest
I want to open a file using OpenFile Dialog class (System.Windows.Forms) in
my ASP.NET application . I don’t want to use file upload control why because
I will not any events from File upload control after selecting the file. I
have to click a button for firing some code in file upload control.
My functionality is by selecting an image it has to load in a Image Control
I have refer the classs System.Windows.Forms nad used the below code
OpenFileDialog of = new OpenFileDialog();
of.Title = "Select a image";
of.InitialDirectory = @"C:\";
of.Filter = " Image files(*.Jpeg)|*.Jpeg";
of.RestoreDirectory = true;
if (of.ShowDialog() == DialogResult.OK)
{
Image1.ImageUrl = of.FileName.ToString();
}
It is working fine my system and when the same code runs in a different
computer I am getting the below error
“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.â€
Also in my system the the dialog box is coming behind of the browser , it
need to come infornt of the browser ( like in File upload)
Can any one suggest the solution for this.
Thanks in advance Umeshnath
my ASP.NET application . I don’t want to use file upload control why because
I will not any events from File upload control after selecting the file. I
have to click a button for firing some code in file upload control.
My functionality is by selecting an image it has to load in a Image Control
I have refer the classs System.Windows.Forms nad used the below code
OpenFileDialog of = new OpenFileDialog();
of.Title = "Select a image";
of.InitialDirectory = @"C:\";
of.Filter = " Image files(*.Jpeg)|*.Jpeg";
of.RestoreDirectory = true;
if (of.ShowDialog() == DialogResult.OK)
{
Image1.ImageUrl = of.FileName.ToString();
}
It is working fine my system and when the same code runs in a different
computer I am getting the below error
“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.â€
Also in my system the the dialog box is coming behind of the browser , it
need to come infornt of the browser ( like in File upload)
Can any one suggest the solution for this.
Thanks in advance Umeshnath