OpenFileDialog - InitialDirectory problem

I have a method that allows a user to open a file. The InitialDirectory property is set at the beginning of the method. If the user selects a file in a different folder, the next time the dialog opens, it opens to the last folder used insted of InitialDirectory folder. How can I stop this?

Thanks

LTCA

[306 byte] By [LTCA-USA] at [2008-1-8]
# 1
Well I found a solution, but it's kind of kludgey. In order to get the OpenFileDialog to 'forget' the last folder it was in and use the same folder everytime (in C#) you have to reset the object and then set all of the properties again.

this.openFileDialog1.Reset();
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Filter = @"ACH files |*.ach|All Files |*.*";
this.openFileDialog1.InitialDirectory = this.SourceFolder;

LTCA

LTCA-USA at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Before you call .ShowDialog on it, you only need to reset the initial directory, and not anything else.

This should reset the InitialDirectory every time:

this.openFileDialog1.InitialDirectory = this.SourceFolder;

Matt_Fomich at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Thanks for the reply. Unfortunately this doesn't work. A button on the form calls the dialog. The first time I click it it opens to the source folder. If I navigate to a different folder and open a file, the next time I click it it opens to the different folder. It alwasys opens to the previous folder used.
LTCA-USA at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

My bad--I was trying it without really opening any file. If you open a file, it behaves as you have said.

It looks like you need this.openFileDialog1.Reset(); which is lame, because then you have to reset everything, as you have stated. I see no way around this.

-Matt-

Matt_Fomich at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic General...