Access Denied on folder after using DirectoryInfo.Delete(true)

  • Thread starter Thread starter Zeb
  • Start date Start date
Z

Zeb

Hi

I'm using DirectoryInfo.Delete so that when a product is removed, all
it's associated images (including the folder they sit in) are deleted.

This actually seems to work fine. However, the folder is not deleted,
but stays and becomes totally locked down. I can no longer open it in
Windows Explorer and when I try to re-launch VS 2005 debug, it
complains because it can no longer monitor that folder .. because it's
denied access.

Any ideas what could be causing this? When the site goes live I don't
want to end up with a load of locked and redundant folders.

I'm guessing it's something to do with the folder being in use by the
..net framework, although I've no idea why it doesn't get deleted. I was
wondering if there's some kind of final cleanup (like a .dispose) I
need to do with the DirectoryInfo object to free up the folder for
deletion?

Any ideas welcome! :)


Thanks,

Matt
 
Just another quick though after sleeping on it!

Could this be because I had previously opened the folder to check that
it exists and contains files? I was doing this to make sure that there
is a folder to begin with and that it's then deleted. When I run the
delete in the web app, I have the parent folder open (ie. the folder
that contains the folder to be deleted).

Could this be causing it to become locked?
 
Any ideas at all?

I've used the same code for associated images with News items as well
as Products and I'm getting exactly the same thing. If I delete a news
item, the images folder for that news item becomes stuck and locked,
which then causes problems with the news page itself.

The one thing I've not tried yet, which I might try in a moment, is to
properly publish the site rather than running in debug and see if that
makes a difference.
 
Well I give up!

In the end I've decided to simply delete the files within the folder,
but leave the folder alone. This is fine as it's the files that take up
all the space.

If anyone does want to have a stab at solving this puzzle, I'd be
interested to hear any ideas.
 

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

Back
Top