It strikes me that System.Windows.Forms.OpenFileDialog seems te
'remember' which directory it was in last, even when a new
OpenFileDialog-object is created for every access to the file system.
This 'persistence' also holds between different invocations of the same
program. Even when the .cs file is re-compiled, the OpenFileDialog again
opens in the directory where it was directed to the previous time.
1. Is this a 'feature' of OpenFileDialog that I can rely upon?
2. If it is a feature, where and how does the OpenFileDialog store its data?
Try it with the small stand-alone program below. Navigate to some
directory and double click an existing file or click 'OK'. Clicking
'Cancel' or hitting 'Escape' does not take you to the new directory.
Then push the Open File... button again and you find yourself in the
previous directory. Cool, but strange.
using System;
using System.Windows.Forms;
class Form1:Form
{
Form1()
{
Controls.Add(new Button());
Controls[0].Text="File Open...";
Controls[0].Click+=ButtonClick;
}
void ButtonClick(object a,EventArgs b)
{
new OpenFileDialog().ShowDialog();
}
[System.STAThread]
static void Main()
{
Application.Run(new Form1());
}
}