473,396 Members | 1,671 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.

Get access denied error when using DirectoryInfo.delete

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 DirectoryInfo(TargetDirectory);
target.Delete(true);

I don’t have problem manually delete the whole directory. Please advice.
Thanks,
Nov 17 '05 #1
7 12109
Charts,

Where is the executable being run from? Is it being run from a network
share, perhaps?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:04**********************************@microsof t.com...
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 DirectoryInfo(TargetDirectory);
target.Delete(true);

I don't have problem manually delete the whole directory. Please advice.
Thanks,

Nov 17 '05 #2
Bry
Random thoughts to follow up on Nicholas' suggestion

Is the directory you are tring to delete empty?

Does your applicaiton (or any other) have a lock on the directory?

Nov 17 '05 #3
The application is a console application and run in the local machine. The
folder to be deleted is a local folder. As I mentioned that I login as
machine administrator account.
The folder is not empty and has both sub directories and files. However I
set flag to true in target.Delete(true). That suppose to delete all sub
directories and files.
Do I need to set up anything in FileIOPermission in order to use
DirectoryInfo class to delete a folder contains files? How do I relate
FileIOPermission class to DirectoryInfo class?
Thanks,
Charts

"Nicholas Paldino [.NET/C# MVP]" wrote:
Charts,

Where is the executable being run from? Is it being run from a network
share, perhaps?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:04**********************************@microsof t.com...
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 DirectoryInfo(TargetDirectory);
target.Delete(true);

I don't have problem manually delete the whole directory. Please advice.
Thanks,


Nov 17 '05 #4
Hi Charts,

Thanks for your feedback.

Yes, this issue is really strange, when you are lauching the application in
local disk with admin account, your application should have full trust CAS
in .Net.

Ok, let's first give a evaluation to your assembly. You can open ".Net
Configuration 1.1" tool from "Administrative tools" in Control Panel. Click
"Runtime Security Policy" node the left panel. Then click "Evaluate
Assembly" link in the right panel.

In the popup dialog, input your assembly path, and click next to evaluate
your assembly permission set. Normally, it should be Unrestricted.

I original suspected that this may caused by Windows NTFS DACL permission,
however, as you said, you can delete this directory manually without any
problem, I just assume that you did not do impersonation in this console
application and it runs under your current login accout. So the NTFS should
not be a problem....

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:04**********************************@microsof t.com...
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 DirectoryInfo(TargetDirectory);
target.Delete(true);

I don’t have problem manually delete the whole directory. Please advice.
Thanks,


Some possible causes:
- The directory is open in the exploere.
- It's the CWD for your console application.
- Another program has a contained file open

Willy.

Nov 17 '05 #6
Thanks Jeffrey for the information. I followed up and checked the assembly
permission. It is unrestricted. So that setting is fine. Actually I find
out that the reason that I cannot delete folder is that some of my files in
the folder are in read only mode. After I set them to normal mode using
“File.SetAttributes(Finfo[i].FullName, FileAttributes.Normal);”
I was able to delete the folder. So the case can be closed now. It is
interesting that it is no where documented that if you use DirectoryInfo
delete method the files in the folder cannot be in read only mode. Thanks for
you help.
Charts.
""Jeffrey Tan[MSFT]"" wrote:
Hi Charts,

Thanks for your feedback.

Yes, this issue is really strange, when you are lauching the application in
local disk with admin account, your application should have full trust CAS
in .Net.

Ok, let's first give a evaluation to your assembly. You can open ".Net
Configuration 1.1" tool from "Administrative tools" in Control Panel. Click
"Runtime Security Policy" node the left panel. Then click "Evaluate
Assembly" link in the right panel.

In the popup dialog, input your assembly path, and click next to evaluate
your assembly permission set. Normally, it should be Unrestricted.

I original suspected that this may caused by Windows NTFS DACL permission,
however, as you said, you can delete this directory manually without any
problem, I just assume that you did not do impersonation in this console
application and it runs under your current login accout. So the NTFS should
not be a problem....

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7
Hi Charts,

Oh, I am glad we finally got the root cause.
Actually, based on my experience, if we are deleting a folder with
read-only files in it, windows explorer will pop-up a warning dialog to
show the read-only information. I think this warning dialog information
should be a good hint to us: there are read-only files in the folder.

Ok, if you need further help, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #8

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

Similar topics

1
by: Theerachet Pratoommanee | last post by:
This is error message I've got. Any suggestion would be appreciated. Server Error in '/WebDirectory' Application. ----------------------------------------------------------------------------...
6
by: Guoqi Zheng | last post by:
Sir, Some times, I developed class library to use on other sites. When I am testing the application, I often get an error of access is denied to that assembly. How can I check the problem? ...
5
by: tshad | last post by:
I am trying to access my log files and am running into a permissions problem. I am doing the following: ****************************************************************** private void...
5
by: wo20051223 | last post by:
Deleting some files with C# fails with "Access to the path 'X' is denied". I have files copied from a CD that I burned (and not locked by a process) and a text file that I created in Windows...
6
by: eswanson | last post by:
on a different server. I am currently getting an access denied when I attempt to do the following in my asp.net page: strFilePath = ConfigurationManager.AppSettings; strFileName =...
1
by: nasirmajor | last post by:
dear all, Please any urgent help regarding following code. i have the following code ================================================================= public void Delete(Object sender,...
4
by: Zeb | last post by:
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...
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...
2
by: RodneyAnonymous | last post by:
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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 projectplanning, 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.