How to determine where SaveFileDialog's initial directory will be?

  • Thread starter Thread starter Richard Lewis Haggard
  • Start date Start date
R

Richard Lewis Haggard

I want to generate a reasonable but unused file name and pass this name in
to a SaveFileDialog. The problem is, I do not seem to be able to figure out
what the SaveFileDialog class is going to use as an initial directory. In
practice, it appears that the class knows where the previous SaveFileDialog
directory was and it reuses it. I want to know where this directory is so
that I can inspect that location and then generate a suggested file name
that is not currently in use.

Here's the current code:
SaveFileDialog saveFileDialog = new SaveFileDialog();
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
// save the project...
}

saveFileDialog.InitalDirectory is an empty string.
Directory.GetCurrentDirectory() is the location of the application.
When the SaveFileDialog actually displays, it uses the last location used by
this application's last invoked SaveFileDialog.

How can I get the directory that SaveFileDialog is going to use before it
uses it? Without this directory, I can't generate an unused file name.
 
Tried that. As I said in the previous post

which is somewhat confusing since the actual initial directory is something
like C:\Junk or where ever the application last displayed the save dialog.
Any other suggestions.
 
Never mind. I got around the problem through code that explicitly determines
this and saves and restores the initial directory in the desired manner.
 
What I meant was, SET the InitialDirectory.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Which is what I ended up doing. My question was poorly worded. What I wanted
to know was, how does one programmatically get the directory that the file
save as directory form is going to use. It seems as though it can be
different from the application directory or the current directory and that
there is no bullet proof fashion that this value can be extracted. In any
case, I came up with a work around that did the trick for me so thanks all,
problem solved.
 
Back
Top