473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Jan 4 '07 #1
4 6712
Zeb
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?

Jan 5 '07 #2
Zeb
I just tried the following:

1. Made sure all folders in windows explorer were closed (so that
folders don't become locked).

2. Uploaded some pictures for a product, so that a folder will be
created for that product.

3. Delete the product so that it's pictures folder will be deleted.

4. Checked to make sure that the product has no picture folder.

I found that the folder for the product was still there, but, as
before, it's locked and I can't open or delete it.

Here's my code. Am I doing something wrong??
int ProductID = (int)e.Keys["ProductID"];
string sFolderPath = Server.MapPath("../img/products/" +
ProductID.ToString() + "/");
System.IO.DirectoryInfo oDir = new
System.IO.DirectoryInfo(sFolderPath);
oDir.Delete(true);
oDir = null;
Zeb wrote:
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?
Jan 6 '07 #3
Zeb
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.

Jan 8 '07 #4
Zeb
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.

Jan 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
7
by: Charts | last post by:
I login as administrator of the machine. However running the following code get access denied exception for file inside the directory. The source code: DirectoryInfo target = new...
2
by: JasonP | last post by:
I want to write a sub that will accept a folder parameter (string, as in: "C:\Temp") and then delete all the files in that folder. Can anyone tell me what a simple way to accomplish this is? I...
30
by: Jason | last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these tests (below), and it doesn't make sense to me. False is equal to 0, and that's fine. True should be equal to 1, but it's...
0
by: MP | last post by:
Hi, I am getting the Access denied Error on a folder after I try to delete a folder that contains some files through my ASP.NET Application. Following is my code DirectoryInfo directoryInfo...
0
by: Michael Sparks | last post by:
Hi, Just thought some people may be interested to hear that I've recently been looking at adding true concurrency into Kamaelia, by using Paul Boddie's pprocess as the core mechanism to allow...
5
by: fniles | last post by:
I am using VB.NET 2005. When I try to delete a folder that has files underneath it, it gave me "the directory is not empty" error. f = New IO.DirectoryInfo("C:\myfolder") If f.Exists Then...
0
by: wolfsbane | last post by:
Alright, here it is I am trying to write a win32 app in VB 2005 to clean up user's profiles. everything works correctly except for the Delete("directory", True) statement. I get a...
2
Haitashi
by: Haitashi | last post by:
I have the following grid: <cfgrid name="gridChartType" delete="true" deletebutton="Remove" insert="true" insertbutton="Add" width="714" height="500" format="flash"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.