File at second call to openfiledialog

Hi,
I'm building a win form application using C# VS 2010. In my main form (= the one that load at start up) Load() event handler I want user to point to some xml files needed. The first one is picked with this code:

            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Filter = "XML File|*.xml";
            fdlg.Title = "Open XML file containing program parameter structure!";
            fdlg.DefaultExt = ".xml";
            fdlg.FileName = Global.globalString + ".xml";
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                string openedFile = fdlg.FileName;
                ix = openedFile.LastIndexOf("\\");
                Global.xmlPath = openedFile.Substring(0, ix);

                xmlReader = new XmlTextReader(openedFile);
                Global.mainXMLDoc.Load(xmlReader);
                xmlReader.Close();

            }
            else
            {
                MessageBox.Show("Failed to open " + Global.globalString + ".xml, please restart application!", "Error loading " + Global.globalString + ".xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

Since I failed to use the same object (fdlg ) twice I tried to define another object and basically doing the same thing as above:

            OpenFileDialog fdlg2 = new OpenFileDialog();

            fdlg2.Title = "Open XML file containing saved filters!";
            fdlg2.Filter = "XML File|*.xml";
            fdlg2.DefaultExt = ".xml";
            fdlg2.FileName = "filter.xml";
            if (fdlg2.ShowDialog() == DialogResult.OK)
            {
                string openedFile = fdlg2.FileName;

                xmlReader = new XmlTextReader(openedFile);
                Global.filterDoc.Load(xmlReader);
            }
            else
            {
                MessageBox.Show("Failed to open Filter.xml, please restart application!", "Error loading " + Global.globalString + ".xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

Now what happens at runtime is that the program hangs at the row  if (fdlg2.ShowDialog() == DialogResult.OK) i.e. ShowDialog method cannot be called twice even if it's used in seperate objects. Or???

BR,
Peer
peer754Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
ShowDialog() is a BLOCKING method, meaning that your application won't do anything until the dialog is closed. That said, are you sure the dialog isn't opening behind your form and you're just not seeing it? This would give the appearance of a program hang due to the blocking nature of ShowDialog().
0
PryratesCommented:
is it possible that the second file open dialog is "just" in the background?

I tried it and the seconds dialog open is not automatically the "top most" window. It is opend in the background so other windows (like the explorer) are in front of the dialog.

Try the following:
minimize ALL windows on your desktop and lauch your application (in built mode - run the "exe"-file).

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peer754Author Commented:
Wow, that's what I call a huge embarrassment :-o ... Yes it was turning up beneath all my other opened windows, simple as that!

THANKS for opening my tired eyes ;)
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

PryratesCommented:
no problem ;-). You were not the first and will not be the last that stumbles upon that bad windows behaviour.
0
peer754Author Commented:
So, isn't it any way I can make the second (why is the second filedialog not top-most?) file dialog top-most so that the user won't have to look for it behind all open windows he might have?

As far as I understand, there's no way to do this except writing your own openfiledialog class, right?
0
peer754Author Commented:
I made a call to the Dispose() method before initalizing the second dialog and that did the trick :D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.