| |

VerySource

 Forgot password?
 Register
Search
View: 875|Reply: 7

OpenFileDialog's ShowDialog method reports an error

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-2 10:00:01
| Show all posts |Read mode
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.
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-3-19 14:45:01
| Show all posts
ShowDialog should be used in WinForm.
To display a file dialog in ASP.NET, you should use Java script.
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-3-19 16:45:01
| Show all posts
Put a line like this in front of your main () function

[STAThread]
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-3-19 22:00:01
| Show all posts
It seems that OpenFileDialog uses File (Input) in ASP.NET.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-4-6 11:30:01
| Show all posts
May
There is no main function in asp.net
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-4-6 20:15:01
| Show all posts
There is a problem with file (input). When the file is larger than 20MB, the page cannot be displayed.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-15 09:45:01
| Show all posts
Add a line of this statement in front of your main() function
[STAThread]
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 16:00:01
| Show all posts
I am C# and I also reported this error. How can I solve it?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list