OpenFileDialog creates handle to a folder

  • Thread starter Thread starter Hayato Iriumi
  • Start date Start date
H

Hayato Iriumi

Hello, folks.
I have an issue with OpenFileDialog. Let's say I chose a file at C:
\TestFolder\TestFile.txt using OpenFileDialog. After I choose the
file, I tried to delete the folder from Windows Explorer, but it says
that another process is being used by another person or program.

So I opened up Process Explorer and checked my Windows application. I
found out that it was holding a handle to the folder that contains the
file I just chose. Whenever I use OpenFileDialog to choose a file, it
seems to create a handle to the folder. I can delete the folder when I
close the application or just close the handle from Process Explorer,
but I need to get around this issue programmatically.

So my question is how do I avoid creating a handle to the folder that
contains the file I chose from OpenFileDialog?
 
After a few hours of poking around, found that RestoreDirectory should
be set to True.
I hope this helps people who are having the same issue.
 
Back
Top