OpenFileDialog.RestoreDirectory no longer works in Vista afterinstalling VS 2008

H

haroldsphsu

Hi all,

I have an app that relies on OpenFileDialog to change the current
working directory based on the user selection (i.e.
OpenFileDialog.RestoreDirectory = false). It was working fine on
WinXP/2003/Vista. But after I install VS 2008 (which also installed
KB110806 (.Net 2.0 Framework SP1), KB929300 (.Net 3.0 Framework SP2)),
the OpenFileDialog no longer changes the current working directory on
Vista. I wrote a sample app to display the current directory before
and after OpenFileDialog, and the sample app works on:

- XP, with KB110806, KB929300 and .Net Framework 3.5 installed.
- 2003, with KB110806, KB929300, .Net Framework 3.5 installed, VS 2008
installed.

but it doesn't work on Vista with VS 2008 installed. Here's the code-
behind:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
_lblBefore.Text =
System.IO.Directory.GetCurrentDirectory();
}

private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
_lblAfter.Text =
System.IO.Directory.GetCurrentDirectory();
}
}

}

Does anyone have a similar problem?
 
R

RobinS

We are using VS2008, but I haven't noticed this. But then, we retain
the last folder the user selected, and set the InitialDirectory before
opening the file dialog the next time...

Good luck.
RobinS.
GoldMail, Inc.
 
J

Jacek Kolonko

Hi.

I have exactly the same issue in my application. CurrentDirecory concept
seems to have changed in a .NET 2.0 Framework Update or Windows Vista SP1. In
previous versions OpenFileDialog changed current directory but now it does
not.

But suprisingly RestoreDirectory works as expected. I created a sample
console app that did nothing but display Directory.GetCurrentDirectory()
right before and after OpenFileDialog.ShowDialog is called (InitialDirecotry
left blank). When you run the app again the OpenFileDialog shows the same
folder in which you selected the file, not the CurrentDirectory. And that IS
consistent with previous versions of Windows because if you run the same app
twice on Windows XP w/.NET 2.0 it shows you the CurrentDirectory before
OpenFileDialog but InitialDirectory changes.

So the change seems to be by design. I wish someone clarified how
FileDialogs are supposed to work to avoid such misconceptions such as relying
on CurrentDir.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top