OpenFileDialog and the current directory

Just found out something odd that I never noticed before.  If you use the OpenFileDialog class to allow a user to select a file, then once they’ve selected a file, the directory that file is in is now your application’s current directory!  Huh?  Seems odd to me.

There’s an easy workaround.  The OpenFileDialog class has a RestoreDirectory property (actually, it comes from the base class FileDialog) which you can set to true to disable this quirky behavior.  Why it defaults to false is something I can’t answer…

Published Tuesday, August 01, 2006 11:04 AM by PSteele

Comments

# re: OpenFileDialog and the current directory

Thanks a lot. :-) I found this problem too and you   solution helped me a lot

Tuesday, October 02, 2007 11:26 AM by Aleks