Http://community.9cbs.net/expert/topic/3472/3472946.xml?temp=.7222864
Create a virtual directory
DirectoryEntry is a big gift to us. His name We know his function - the directory entrance. People who have used ADSI know that when operating IIS, Winnt, we also need to provide their PATH, when operating IIS, this PAT is:
IIS: // computername / service / Website / Directory
Computername: The name of the server that is operated, can be named or IP, often use Localhost
Service: That is, the server, IIS has web, also has FTP, and SMTP these services, we mainly operate the web function of IIS, so "W3SVC", if it is FTP, it should be "MSFTPSVC"
Website: A lot of sites can be included in an IIS service, which is used to set the site. His value is a number, default is 1, indicating the default site, if there is anything, then push from 1.
Directory: Don't say, the directory name of the operation, a site general top-level directory is "root", and other directory is his child (Child).
First we get a top-level directory of a site (root directory):
DirectoryEntry Rootfolder = New DirectoryEntry ("IIS: // LocalHost / W3SVC / 1 / ROOT");
If we create this object, it does not have an exception, it means that this directory is true.
Let's add a new virtual directory, such as what we have to add "ASPCN":
DirectoryEntry newvirdir = rootfolder.children.add ("aspcn", "iiswebvirtualdir");
NewVirdir.Invoke ("AppCreate", TRUE;
Newvirdir.commitchanges ();
Rootfolder.commitchanges ();
The idea of creating a directory is simple, that is, add a record in the subset of the root directory (rootfolder.children), use the add method in the DirectoryEntries class, which returns a directoryentry, indicating the newly added directory, A parameter is the name of the virtual directory, the second is the class name of Schema to indicate the type of directory we join. Then use DirectoryEntry's Invoke method, call the "AppCreate" method in ADSI to truly create (seek not going this step can also create a directory success, but for insurance, everyone still uses it), and finally call new, The COMMITCHANGES method of the root directory confirms this operation.
When you create a new directory, we can also assign a value to this directory at the same time, but my actual experience tells me that it is best not to do this. If you create it, you will have a lot of attributes that you can't assign a value, such as important representation. The PATH property of the directory. So the flying knife suggests that everyone is best to create a directory, then assign the value, that is, update the directory information.
Update virtual directory
I believe that everyone is familiar with IIS, understands some important settings in IIS, such as AccessRead, writable (AccessExecute), etc. These can be implemented by assigning the DirectoryEntry's Properties attribute set. Assignments can be completed in two ways: The first is the Add method of calling the Properties collection, such as:
Dir.properties ["AccessRead"]. Add (true);
The second is to assign the first index value:
Dir.properties ["AccessRead"] [0] = TRUE;
Both methods are feasible. Specifically, you have to look at your preference.
We still have to assign the target to assign a value before you assign a value :) Here we use the DirectoryEntries class Find method, such as:
DirectoryEntry de = rootfolder.children.find ("ASPCN", "Iisvirtualdir");
Found, we can assign it. Be sure to look at it when you assign a value, the attribute value of the virtual directory can be super, and a lot is checked. . :( Too much, I don't repeat it, everyone goes to Microsoft's site :)
Comparable: AccessRead, Accesswrite, AccessExecute, Accessscript, Defaultdoc, Enabledefaultdoc, Path
Delete virtual directories
The way to delete the virtual directory is also very simple, that is, find the virtual directory you want to delete, then call the AppDelete method.
DirectoryEntry de = rootfolder.children.find ("ASPCN", "Iisvirtualdir");
de.invoke ("Appdelete", True;
Rootfolder.commitchanges ();
There is also a way to call the DELETE method for the root directory.
Object [] Paras = New Object [2];
Paras [0] = "IisWebVirtualDir"; // means operation is a virtual directory
Paras [1] = "ASPCN";
Rootfolder.Invoke ("delete", parac;
Rootfolder.commitchanges ();