|
-
November 11th, 2008, 12:15 PM
#1
DirectoryEntry for a single file
How can one set security on single file?
I'm trying to set the security permissions on an individual file on IIS. I've already used DirectoryEntry and it's Properties collection to set permissions at directory level but can't get it for file only, first of all I cannot new a DirectoryEntry with the url of a file, secondly if I new up a DirectoryEntry with the directory and then look for the Children it also fails, the debugger shows me an exception is thrown when trying to access the Children collection,
Code:
string myfileurl = url + "/myfile.asmx";
//if (DirectoryEntry.Exists(myfileurl))//fails
if (DirectoryEntry.Exists(url))
{
DirectoryEntry entry = new DirectoryEntry(url);
DirectoryEntry myfilesEntry = entry.Children.Find("myfile.asmx", "");//fails, Children throws an exception
PropertyCollection props = myfilesEntry.Properties;
Int32 currentValue = (Int32)props["AuthFlags"].Value;
entry.Properties["AuthFlags"][0] = 4;
entry.CommitChanges();
}
-
November 11th, 2008, 05:43 PM
#2
Re: DirectoryEntry for a single file
-
November 12th, 2008, 05:02 AM
#3
Re: DirectoryEntry for a single file
the Find throws a DirectoryNotFoundException, when I look at the Children in the debugger the Count property has thrown a NotImpementedException with the message "The method or operation is not implemented.".
Could this mean that DirectoryEntry.Children.Find will only find child directories and not files?
The answer appears to be Yes.
A simple foreach shows the children as the directories only:
foreach(DirectoryEntry childEntry in entry.Children)
{
Console.WriteLine(" child: " + childEntry.Name);
}
results:
App_Code
bin
Last edited by ireland; November 12th, 2008 at 05:19 AM.
Reason: addition
-
November 12th, 2008, 10:38 AM
#4
Re: DirectoryEntry for a single file
Take a look at the DirectoryInfo and FileInfo classes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|