How can we change the property of one subdirectory of the Virtual
Directory?
One of the directories should be granted "Write".
You can use ADSI to examine and set properties on a virtual directory.
The relevant classes live in the System.DirectoryServices namespace -
you'll need to add a reference to that assembly to your C# project.
If you already have a virtual directory and you just want to change
some setting, proceed as follows:
1) Bind to the virtual directory ("MyDir" for this sample) - you need
to know the web server name ("MyServer" for this sample), and the web
number (usually 0):
DirectoryEntry deVDir = new
DirectoryEntry("IIS://MyServer/W3SVC/0/Root/MyDir");
2) If the bind succeeded, you should be able to access the properties
of the VDir through the DirectoryEntry:
if(deVDir != null)
{
string sPhysicalDir = deVDir.Properties["Path"][0].ToString();
}
3) There is a large number of properties on the VDir - those of
interest to you will be AccessRead, AccessWrite, AccessScript,
AccessExecute and AccessSource. Those are of type boolean, and from
what I see, you need to put a value of "0" in them for false, -1 for
true.
You can modify these properties like this:
deVDir.Properties["AccessWrite"].Value = -1;
and then you need to persist the changes
deVDir.CommitChanges();
That should allow you to "save" your existing VDir and set the
properties according to your needs.
For more info on System.DirectoryServices, see the S.DS portal at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/portal.asp
Unfortunately, the chapter on "Using System.DirectoryServices to
Configure IIS" is still missing after all those months.....
Cheers!
Marc