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

后端 未结 2 736
孤城傲影
孤城傲影 2021-02-18 22:30

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 t

相关标签:
2条回答
  • 2021-02-18 23:07

    FileDialog (the base class of OpenFileDialog) has a property called AutoUpgradeEnabled which controls whether the dialog takes advantage of the newer file dialogs that were implmented in Vista and newer operating systems when they are available. (Internally this is the difference between calling GetOpenFileName in comdlg32 or in using the IFileDialog interface).

    The reason for doing this is that the newer dialogs support a number of features like the "places" bar (see the CustomPlaces collection). An unexpected side effect of this is that the newer IFileDialog implementation does not change the current directory whereas the older version did.

    This is a bug in the file dialog implementation and happens regardless of the value of the RestoreDirectory property

    If you don't want to use the newer file dialog functionality, the easiest thing to do is to set the AutoUpgradeEnabled to false.

    0 讨论(0)
  • 2021-02-18 23:14

    Based on your description it sounds like the default value of the RestoreDirectory property is different between XP and Windows7. I'm not sure why this would be the case but you can fix this problem by explicitly setting the value in your code. Setting it to true will restore the directory on dialog close.

    0 讨论(0)
提交回复
热议问题