2016-08-12 4 views
0

私はWin8デスクトップ上のC#.NET/Formsでログビューアアプリケーションを作成しています。OpenFileDialogを%temp%にしたことを覚えておくには?

System.Windows.Forms.OpenFileDialogを使用するときに問題があります。 %temp%ディレクトリからファイルを選択して「OK」をクリックし、別のファイルを選択する場合、OpenFileDialogは最後に%temp%ディレクトリにアクセスしたことを覚えていません。私のアプリケーションは通常、%temp%からのさまざまなログファイルを開くので、私は最後に訪れた非%temp%ディレクトリを表示することに変わります。

Precondition: - OpenFileDialog created and existing. - OpenFileDialog has InitialDirectory = "C:\" Scenario: - ShowDialog(): Displays C:\ - OK. - Change directory to C:\logfiles\test.txt and click OK to close. - ShowDialog(): Displays C:\logfiles\ - OK. - Change directory to %temp% (which expands to C:\Users\joe\AppData\Local\Temp) and click OK to close. - ShowDialog(): Displays C:\logfiles\ - FAIL! Here it should show C:\Users\joe\AppData\Local\Temp but it doesn't. It reverts to the last directory I selected that is not in %temp%. Why?

質問:どのようにこの動作を防ぐには?

+0

以下のリンクを確認してください。 http://stackoverflow.com/questions/17121296/openfiledialog-restoredirectory-files-for-temp-location-bug-or-feature – zahed

+1

'FileDialog.RestoreDirectory'プロパティを使用して、最後のディレクトリを覚えておくことができます。代わりに 'IntiialDirectory'を使って開くこともできますが、これらの2つが衝突する可能性があります - 最後のディレクトリを覚えておく変数を設定することもできます:)実際に何も投稿していないので、コードですが、たとえば:var ofd = new OpenFileDialog(); ofd.RestoreDirectory = true; ' –

+1

viriousによって既に[ここ](http://stackoverflow.com/a/16078701/2503977)に回答済みです。 – Toastgeraet

答えて

関連する問題