Why the current working directory changes when use the Open file dialog in XP?

Posted by RRUZ on Stack Overflow See other posts from Stack Overflow or by RRUZ
Published on 2010-06-10T22:22:12Z Indexed on 2010/06/10 22:32 UTC
Read the original article Hit count: 321

Filed under:
|
|

I have found an strange behavior when use the open file dialog in c#.

If use this code in Windows XP the current working directory changes to the path of the selected file, however if you run this code in windows 7 the current working directory does not change.

    private void button1_Click(object sender, EventArgs e)
    {            
        MessageBox.Show(string.Format("Current Directory {0}",Directory.GetCurrentDirectory()), "My Application",MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog and get result.
        if (result == DialogResult.OK) 
        {

        }
        MessageBox.Show(string.Format("Current Directory {0}", Directory.GetCurrentDirectory()), "My Application", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    }

Anybody know the reason for this behavior? Why the current directoiry changes in XP and not in windows 7?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET