Why does OpenFileDialog change my working directory?

user34537 picture user34537 · May 31, 2009 · Viewed 11.2k times · Source

Why does OpenFileDialog change my working directory? Should i assume many func in System.Windows.Forms will change my working directory?

    OpenFileDialog open = new OpenFileDialog();
    open.Filter = filter;
    a = Directory.GetCurrentDirectory(); //<-- correct
    if (open.ShowDialog() == DialogResult.OK) //-- select a file on my desktop
    {
        a = Directory.GetCurrentDirectory(); //<-- incorrect, is set to my desktop

Answer

Mike picture Mike · Oct 9, 2009

Or you can make it not do that. See the FileDialog.RestoreDirectory property.