Delete Virtual Directory and related Folder


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Delete Virtual Directory and related Folder

  1. #1
    Join Date
    Dec 2004
    Posts
    717

    Delete Virtual Directory and related Folder

    System.DirectoryServices.DirectoryEntry iISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + sWebSite + "/W3SVC/1/Root");

    string sWebPath = iISAdmin.Properties["Path"].Value.ToString();

    //If the virtual directory already exists then delete it
    foreach(System.DirectoryServices.DirectoryEntry vd in iISAdmin.Children)
    {
    if(vd.Name==sAppName)
    {
    sWebPath += "\\" + vd.Name;
    *****
    sWebPath=vd.Properties["Path"].Value.ToString();
    iISAdmin.Invoke("Delete", new string[]{vd.SchemaClassName, sAppName}); System.IO.Directory.Delete(sWebPath); iISAdmin.CommitChanges();
    break;
    }
    }
    I like to check whether "Path" property of vd is exists or not. like the following coding in ***** position.
    if(((System.DirectoryServices.PropertyCollection)((vd.Properties))).valueTable.Count > 0 )
    I wrote this coding in windows application.
    Last edited by Sync; 11-17-2005 at 08:38 AM.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  2. #2
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    Seems useful because till date i was using a vbscript file to do this from a cscript console.. I am not sure if you had a question.. seems like you are asking how to know if the propertycollection has a property or not?
    Sri

  3. #3
    Join Date
    Dec 2004
    Posts
    717
    Yeah.Srinivas. I like to ask how to know if the the propertycollection has a property or not?
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  4. #4
    Join Date
    Dec 2004
    Posts
    717
    The virtual directory that is created by Visual Studio 2003, is lit bit different than the virtual directory that is made as Web Sharing from Folder Properties.
    I found one useful facts after I have checked the differences between two types of virtual directories using metaedit2.2. If the vd is created by VS2003, the data of "keyType" Key of this virtual directory will be "IIsWebDirectory". Likewise, If the vd is made as Web Sharing, the data of "keyType" Key of this virtual directory will be "IIsWebVirtualDir". So, we can know whether we need to check the path property or not by checking the data of "KeyType".

    Deleting Virtual Directory...
    System.DirectoryServices.DirectoryEntry iISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + sWebSite + "/W3SVC/1/Root");

    string sWebPath = iISAdmin.Properties["Path"].Value.ToString();

    //If the virtual directory already exists then delete it
    foreach(System.DirectoryServices.DirectoryEntry vd in iISAdmin.Children)
    {
    if(vd.Name==sAppName)
    {
    sWebPath += "\\" + vd.Name;

    if(vd.KeyType == "IIsWebVirtualDir")
    sWebPath=vd.Properties["Path"].Value.ToString();

    iISAdmin.Invoke("Delete", new string[]{vd.SchemaClassName, sAppName});
    System.IO.Directory.Delete(sWebPath);
    iISAdmin.CommitChanges();

    break;
    }
    }
    Last edited by Sync; 11-19-2005 at 01:09 AM.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

Similar Threads

  1. Replies: 2
    Last Post: 09-08-2005, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center