How to set properties using DirectoryEntry object

How to set properties using DirectoryEntry object

Post by Alex » Fri, 16 May 2003 04:45:16



I am using a DirectoryEntry object to try to create a virtual directory, but
I need to set properties as well as invoke methods on the IIS provider, how
do I do this?

obDirEntry = new DirectoryEntry("IIS://" + strServer + "/W3svc/1/Root");

// create new dir

oWebDir = obDirEntry.Invoke("Create", "IIsWebVirtualDir", "NewVDir") as
DirectoryEntry;

oWebDir.Properties["Path"] = "c:\\inetpub\\wwwroot\\NewContent";

oWebDir.Properties["AccessRead"] = "True";

oWebDir.Properties["AccessScript"] = "True";

oWebDir.Invoke("AppCreacte2", "1");

oWebDir.Properties["AppFriendlyName"] = "NewApp";

oWebDir.Invoke("SetInfo");

 
 
 

How to set properties using DirectoryEntry object

Post by Alex » Fri, 16 May 2003 06:26:21



Quote:> I am using a DirectoryEntry object to try to create a virtual directory,
but
> I need to set properties as well as invoke methods on the IIS provider,
how
> do I do this?

> obDirEntry = new DirectoryEntry("IIS://" + strServer + "/W3svc/1/Root");

> // create new dir

> oWebDir = obDirEntry.Invoke("Create", "IIsWebVirtualDir", "NewVDir") as
> DirectoryEntry;

> oWebDir.Properties["Path"] = "c:\\inetpub\\wwwroot\\NewContent";

> oWebDir.Properties["AccessRead"] = "True";

> oWebDir.Properties["AccessScript"] = "True";

> oWebDir.Invoke("AppCreacte2", "1");

> oWebDir.Properties["AppFriendlyName"] = "NewApp";

> oWebDir.Invoke("SetInfo");

never mind, I had to use the index operator [0] to set the property...

F.e.,

oWebDir.Properties["AccessScript"][0] = "True";

 
 
 

How to set properties using DirectoryEntry object

Post by Marc Scheuner [AD MVP » Fri, 16 May 2003 16:52:09


Quote:>> oWebDir = obDirEntry.Invoke("Create", "IIsWebVirtualDir", "NewVDir") as
>> DirectoryEntry;
>> oWebDir.Properties["Path"] = "c:\\inetpub\\wwwroot\\NewContent";
>> oWebDir.Properties["AccessRead"] = "True";

>never mind, I had to use the index operator [0] to set the property...
>F.e.,
>oWebDir.Properties["AccessScript"][0] = "True";

Yes - if you want to overwrite the first entry of that multi-valued
property. Many properties in LDAP are multi-valued, e.g. they can
contain more than one entry, things like "telephoneNumber" on the user
object.

Of course, using the [0] specifier and assigning a new value to it
will always overwrite the first entry in that list of property values
- if that's what you want, you're fine - but you may not.

If you want to *add* a new (second, third, etc.) entry to the
multi-valued property, check into the
Properties["telephoneNumber"].Add(value) method. If you want to check
whether or not a property (collection) contains a specific value, call
the Properties["telephoneNumber"].Contains(value) method. You get the
picture.....

Marc

================================================================
Marc Scheuner                        May The Source Be With You!
Bern, Switzerland                         m.scheuner(at)inova.ch