ireland
November 11th, 2008, 11:15 AM
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,
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();
}
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,
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();
}