Home>
using system;
using system.directoryservices;
using system.collections.generic;
using system.text;
namespace consoleapplication1
{
  class program
  {
    static void main (string [] args)
    {
      directoryentry rootentry=new directoryentry ("iis://localhost/w3svc");
      int siteid=1;
      foreach (directoryentry entry in rootentry.children)
      {
        if (entry.schemaclassname.equals ("iiswebserver", stringcomparison.ordinalignorecase))
        {
          console.writeline ("name:{0}", entry.name);
          console.writeline ("path:{0}", iisworker.getwebsitephysicalpath (entry));
          console.writeline ("serverbindings:{0}", entry.properties ["serverbindings"]. value);
          console.writeline ();
          directoryentry virentry=new directoryentry (entry.path + "/root");
          foreach (directoryentry entryvirtual in virentry.children)
          {
            if (entryvirtual.schemaclassname.equals ("iiswebvirtualdir", stringcomparison.ordinalignorecase))
            {
              console.writeline ("schemaclassname:{0}", entryvirtual.schemaclassname);
              console.writeline ("name:{0}", entryvirtual.name);
              console.writeline ("path:{0}", entryvirtual.properties ["path"]. value);
              console.writeline ();
            }
          }
          int id=convert.toint32 (entry.name);
          if (id>= siteid)
          {
            siteid=id + 1;
          }
        }
      }
    }
  }
  public class iisworker
  {
    ///<summary>
    ///Get the physical path of the website
    ///</summary>
    ///<param name="rootentry">site node</param>
    ///<returns></returns>
    public static string getwebsitephysicalpath (directoryentry rootentry)
    {
      string physicalpath="";
      foreach (directoryentry childentry in rootentry.children)
      {
        if ((childentry.schemaclassname == "iiswebvirtualdir")&&(childentry.name.tolower () == "root"))
        {
          if (childentry.properties ["path"]. value!=null)
          {
            physicalpath=childentry.properties ["path"]. value.tostring ();
          }
          else
          {
            physicalpath="";
          }
        }
      }
      return physicalpath;
    }
  }
}
c
  • Previous Java random read and write of files and compression processing operations
  • Next JSP method for quickly uploading files