The following is taken from http://www.eggheadcafe.com/articles/20040112.asp
Using system; using system.directoryservices;
Namespace Iismgraddin {///// Summary Description for iismanager {///////////////////////////// PubliciSManager ( ) {} public string CreateVDir (string WebSite, string VDirName, string Path, bool RootDir, bool chkRead, bool chkWrite, bool chkExecute, bool chkScript, bool chkAuth, int webSiteNum, string serverName) {string sRet = String.Empty; System. DirectoryServices.directoryEntry IissChema; System.directoryServices.directoryEntry Iisadmin; System.directoryServices.DirectoryEntry Vdir; Bool iiSunder;
// // determine version of iis // iisschema = new system.directoryServices.directoryEntry ("IIS: //" servername "/ schema / appisolated"); if (iisschema.properties ["syntax"]. Value.toString () .Toupper () == "boolean") iiSundernt = true; else iisundernt = false; iisschema.dispose ();
/// Get the Admin Object // Iisadmin = New System.directoryServices.directoryEntry ("IIS: //" ServerName "/ W3SVC /" WebsitEnum "/ root");
// // If we're not creating a root directory // if (! RootDir) {// // If the virtual directory already exists then delete it // foreach (System.DirectoryServices.DirectoryEntry v in IISAdmin.Children) { if (v.Name == VDirName) {// Delete the specified virtual directory if it already exists try {IISAdmin.Invoke ( "Delete", new string [] {v.SchemaClassName, VDirName}); IISAdmin.CommitChanges (); } Catch (Exception EX) {SRET = EX.MESSAGE;}}}} //// ' {Vdir = Iisadmin;
/// // setup the vdir // vdir.properties ["accessread"] [0] = chkread; vdir.properties ["accessexecute"] [0] = Chkexecute; vdir.properties ["accesswrite] [0] = chkwrite ; VDir.Properties [ "AccessScript"] [0] = chkScript; VDir.Properties [ "AuthNTLM"] [0] = chkAuth; VDir.Properties [ "EnableDefaultDoc"] [0] = true; VDir.Properties [ "EnableDirBrowsing" ] [0] = false; vdir.properties ["defaultdoc"] [0] = true; vdir.properties ["path"] [0] = path;
//////////Ww (! IiSundernt) {vdir.properties ["aspenableparentpaths"] [0] = true;
//// set the change the changes // vdir.commitchanges ();
// // make it it a web application // if (iiSundernt) {vdir.invoke ("appcreate", false);} else {vdir.invoke ("appcreate", 1);}
sRet = "VRoot" VDirName "created!"; return sRet;} #region Properties public string ServerName {get {return _serverName;} set {_serverName = value;}} #endregion public static string VirDirSchemaName = "IIsWebVirtualDir"; # Region private memory private string _servername; #endregion}}
The following is a reference method:
public void Exec (string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) {handled = false; if (executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault) {if (commandName == "MyAddin1.Connect .Iismgraddin ") {iismgraddin.frmismgr fm = new iismgraddin.frmismgr (); frm.show (); handled = true; return;}}}