I'm making a log viewer application in C#.NET/Forms on Win8 desktop.
I have a problem when using the System.Windows.Forms.OpenFileDialog. If I select a file from the %temp% directory and click OK, and then want to select another file, the OpenFileDialog refuse to remember that I last visited the %temp% directory. It always reverts to displaying the last non-%temp% directory I visited, which is very annoying since my app typically opens various log files from %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?
Question: How to prevent this behavior?