473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

OpenFileDialog Retains Data?

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());
}
}

Sep 24 '07 #1
3 3209

"Martijn Mulder" <i@mwrote in message
news:46***********************@news.wanadoo.nl...
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?
As I recall, the "remembering" is done in the Registry, is keyed to the type
of file (the extension), and the exact behavior depends on the version of
Windows. Actually, I find it mildly annoying not to have more control over
it. There is a Knowledge Base article about it somewhere on
support.microsoft.com.

The .NET OpenFileDialog is merely a wrapper over the Win32 OpenFileDialog,
as I recollect.
Sep 24 '07 #2
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.
"OpenFileDialog" and "SaveFileDialog" are just wrappers around
"GetOpenFileName()" and "GetSaveFileName()" in the WinAPI. The various
properties seen in the former two classes (such as "InitialDirectory")
really correspond to the appropriate member(s) of the OPENFILENAME structure
passed to the WinAPI functions (such as "lpstrInitialDir"). You can
therefore get a better understanding of the behaviour by reviewing the
OPENFILENAME structure directly (though MSFT should really publish this info
in the .NET docs). As for where this info is actually stored, it's unlikely
MSFT officially publishes it. Even if you can find a reference to a registry
key somewhere (presumably it exists here), you better make sure it's
official before you start monkeying around with it (which isn't a good idea
anyway - you should normally control things using the official API)
Sep 24 '07 #3
Hi,

"Martijn Mulder" <i@mwrote in message
news:46***********************@news.wanadoo.nl...
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?
Remember that the .net version of the dialog is just a wrap around the win32
version of it.
It's the unmanaged version the one that keep the reference of where it was
was the last time it was used.

You can rely upon it, but just remember this is a system wide setting, if
another program change it the next time yours call it it will have a
different location
Sep 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jody Gelowitz | last post by:
VS.NET 2002 and 2003 are installed. ..NET Framework 1.0 and 1.1 installed Program running under VisualBasic.NET 2002 with .NET Framwork 1.0 I am experiencing a problem with ADO.NET where the...
3
by: bobrad | last post by:
MAYBE SOMEBODY CAM HELP I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM DIALOG OpenFileDialog openFileDialog = new OpenFileDialog(); OpenFileDialog.Filter = " Access...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
8
by: e-mid | last post by:
why does not openFileDialog have closed event? i want to do something; as soon as the dialog closes. is there a way to do this?
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
3
by: Jon | last post by:
Hi, I am scratching all my hair out and really have no idea what is happening with my program... I have a dataset, and i used dataAdapter to fill the data. Everything works fine until I run...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
0
by: Gregaz | last post by:
I have a form in my project, which I open as a DialogBox. On that that form there are 3 TextBoxes. To one of them I want to write in a file path. To have it easier I have an OpenFileDialog control...
9
by: Sagaert Johan | last post by:
Hi Can i extend the OpenFileDialog so i can show a thumbnail of a picture i am opening ? (priview it in a picturebox inside the fileopen dialog ) Johan
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.