ITコンサルの日常

ITコンサル会社に勤務する普通のITエンジニアの日常です。

SaveFileDialogを使うとフォルダがロックされる件

保存先を選んでOKすると(キャンセルの場合は大丈夫)フォルダがロックされ、削除やリネームができなくなります。
30分ほどGoogleと格闘した結果、ようやく次のエントリを見つけました。

Short from mis-behaving shell extensions, this is normal. SFD will change the current working directory of your program to the directory that contains the file selected by the user. And that puts a lock on the directory.

You avoid this by setting the RestoreDirectory property to True.

つまり、RestoreDirectoryプロパティをTrueにしろってことです。
やってみたところ確かにうまく行きました。でも、なんでデフォルトでこんな挙動なんでしょうね。。