Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using DialogResult.OK in OpenFileDialog

I copied a OpenFileDialog from one of my other projects but it does not work on the new project.

 OpenFileDialog open = new OpenFileDialog();
        open.Filter = "Binary|*.bin";
        open.RestoreDirectory = true;
        open.Multiselect = false;
        try
        {
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
               //some code
            }
        }...

The Error says that I'm missing a reference. So i tried to configure the references, but when i click the checkbox for System.Windows.Forms it says that I can not use it because the ActiveX-Library was importet from a .NET-Assembly and that it can not be added. In my previous project i added the reference and everything works fine. How can i add a reference to a .NET-Assembly?

Bonus: Why is this happening? Is there any reason why adding a reference should be blocked within VisualStudio?

-Edit- It is a WPF-App and I am using VisualStudio 2017 with .NET Framework 4.5.2

like image 840
Thomas Avatar asked Mar 03 '26 16:03

Thomas


1 Answers

Try replacing the winform reference with false.

Change this

if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)

to this

if (open.ShowDialog() == true)
like image 121
Harsh Avatar answered Mar 05 '26 06:03

Harsh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!