OpenFileDialog won't release folder?

S

sam

OpenFileDialog appears to be "holding onto" the parent folder of a
selected file until the application using the dialog quits.

After creating a folder containing a file, I attempted to select that
file with an OpenFileDialog. I used the following code to create the dialog:

Dim a As New OpenFileDialog
a.ShowDialog()
a.Dispose()

When the OpenFileDialog appears, navigate to the file within the folder
and click “Open”.

Leaving the application still running, attempt to delete the Folder
containing this file. On my machine, it fails with “Cannot delete
'myfoldername': It is being used by another person or program"...

Why is this? I haven’t attempted to actually open the file; merely
selected it. It appears as though the OpenFileDialog box is holding onto
the containing folder until the application is closed, afterwhich the
folder can be deleted. Disposing of the OpenFileDialog doesn’t seem to
help either. However, the actual selected file is not being locked--only
the parent folder.

Any ideas what might be causing this?
 
A

Armin Zingler

sam said:
OpenFileDialog appears to be "holding onto" the parent folder of a
selected file until the application using the dialog quits.

After creating a folder containing a file, I attempted to select
that file with an OpenFileDialog. I used the following code to
create the dialog:

Dim a As New OpenFileDialog
a.ShowDialog()
a.Dispose()

When the OpenFileDialog appears, navigate to the file within the
folder and click “Open”.

Leaving the application still running, attempt to delete the Folder
containing this file. On my machine, it fails with “Cannot delete
'myfoldername': It is being used by another person or program"...

Why is this? I haven’t attempted to actually open the file; merely
selected it. It appears as though the OpenFileDialog box is holding
onto the containing folder until the application is closed,
afterwhich the folder can be deleted. Disposing of the
OpenFileDialog doesn’t seem to help either. However, the actual
selected file is not being locked--only the parent folder.

Any ideas what might be causing this?

What does CurDir return after a.dispose? Have you tried setting
a.RestoreDirectory = True before a.Showdialog? If it is False, the current
directory changes to the directory of the selected file, thus it can not be
deleted. It is not the OpenFileDialog that locks the directory, it's because
the process's current (working) directory has been changed.


Armin
 

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