IO Common Dialogs

  • Thread starter Thread starter Andy Janssen
  • Start date Start date
A

Andy Janssen

First off, is there such a thing as a common dialog that allows a user to select a directory? (I don't think so). Is there any standard way to do so?
Second question. Why does the FileDialog lock down directories contianing the file that the user selects?
Ex:
Directory.Move("C:\\test dir", "C:\\test dir moved"); //Move a file
Directory.Move("C:\\test dir moved", "C:\\test dir"); //Move it back

FileDialog dlg = new OpenFileDialog();
dlg.ShowDialog(this);

// (User selects a file inside c:\test dir\)

// Now let's try to make dlg let go of all handles.
dlg.FileName = "";
dlg.Reset();
dlg.Dispose();
dlg = null;
GC.Collect(); // The dlg object had better be gone by this point!

Directory.Move("C:\\test dir", "C:\\test dir moved");
The first two Directory.Move operations work fine. The last one tells me that the directory "C:\test dir" is in use. What's going on? I realize that this could be some sort of safety or something, but what event turns the directory lock off? I garbage collect the freaking thing! How much more do you want from me!? lol.

Thanks guys.

-Andrew Janssen
 
Well, your answers basically:
1: In framework 1.1 there is the FolderBrowserDialog.
2: Have you checked to make sure that FileDialog isn't changing the current
working directory of your application? That may be the problem. Also, even
though you forced a collect there is no guarentee that the object was
actually collected. It is possible it is still alive for some reason or
another.

Also, if you can, please post in plain text, its easier to reply to and more
broadly readable.



First off, is there such a thing as a common dialog that allows a user to
select a directory? (I don't think so). Is there any standard way to do so?
Second question. Why does the FileDialog lock down directories contianing
the file that the user selects?
Ex:
Directory.Move("C:\\test dir", "C:\\test dir moved"); //Move a file
Directory.Move("C:\\test dir moved", "C:\\test dir"); //Move it back

FileDialog dlg = new OpenFileDialog();
dlg.ShowDialog(this);

// (User selects a file inside c:\test dir\)

// Now let's try to make dlg let go of all handles.
dlg.FileName = "";
dlg.Reset();
dlg.Dispose();
dlg = null;
GC.Collect(); // The dlg object had better be gone by this point!

Directory.Move("C:\\test dir", "C:\\test dir moved");
The first two Directory.Move operations work fine. The last one tells me
that the directory "C:\test dir" is in use. What's going on? I realize that
this could be some sort of safety or something, but what event turns the
directory lock off? I garbage collect the freaking thing! How much more do
you want from me!? lol.
Thanks guys.
-Andrew Janssen
 
2: Have you checked to make sure that FileDialog isn't changing the
current
working directory of your application? That may be the problem. Also, even
though you forced a collect there is no guarentee that the object was
actually collected. It is possible it is still alive for some reason or
another.

Indeed it should be sufficient to use Environment.CurrentDirectory to change
the current directory to its parent directory (you cannot delete the current
directory). As an alternative, you might also want to just set
dlg.RestoreDirectory to true, if this fits your purpose.

Fabian
 
Back
Top