how to delete the virtual directory with the vb.Net ?RSS

1 reply

Last post May 29, 2004 07:49 AM by CodeInTheBottle

  • how to delete the virtual directory with the vb.Net ?

    May 25, 2004 10:08 PM|chenggf2|LINK

    Hi All. I has been successful to Create the virtual directory of "mytest" with the function of "Create()",but I don't delete the "mytest" with the function of "delete1()" or "delete2()" or "delete3()" or "delete4()" Thanks all. chenggf Public sub Create() Dim strPath As String = "IIS://localhost/W3SVC/1/ROOT/mytest" Dim newVirDir As DirectoryEntry = rootfolder.Children.Add(mytest, "IIsWebVirtualDir") newVirDir.Invoke("AppCreate", True) newVirDir.CommitChanges() rootfolder.CommitChanges() end sub public sub delete1() Dim de As DirectoryEntry = rootfolder.Children.Find("mytest", "IIsWebVirtualDir") de.Invoke("AppDelete", True) de.DeleteTree() Dim de As DirectoryEntry = rootfolder.Children.Find("mytest", "IIsWebDirectory") de.Invoke("AppDelete", True) de.DeleteTree() end sub public sub delete2() Dim de As DirectoryEntry = rootfolder.Children.Find("mytest", "IIsWebDirectory") de.Invoke("AppDelete", True) de.DeleteTree() end sub public sub delete2() Dim de As DirectoryEntry = rootfolder.Children.Find("mytest", "IIsWebDirectory") de.Invoke("AppDelete", True) de.DeleteTree() end sub public sub delete3() paras(0) = "IIsWebVirtualDir" paras(1) = "mytest" rootfolder.Invoke("Delete", paras) rootfolder.CommitChanges() end sub public sub delete4() paras(0) = "IIsWebDirectory" paras(1) = "mytest" rootfolder.Invoke("Delete", paras) rootfolder.CommitChanges() end sub Edit by moderator - NetProfit: added < code> tags. Please use them!
  • Re: how to delete the virtual directory with the vb.Net ?

    May 29, 2004 07:46 AM|CodeInTheBottle|LINK

    The problem in delete1 and delete2 is, that the deletetree function doesn´t work with IIS. The problem with delete3 and delete 4 is that the path to the DirecotryEntry maybe incomplete. Try this solution (it worked for me fine for websites): Dim w3svc=new DirectoryEntry("IIS://localhost/w3svc","youruser","yourpassword") 'Nice code below, does the Find method really work ? Never used it.... I´ll have to try it.... Dim de As DirectoryEntry = w3svc.Children.Find("mytest", "IIsWebVirtualDir") 'OK, if the line above works, then ... Dim Params() as object={"IIsWebVirtualDir",de.name} 'it seems to be important to free the binding to the object, otherwise IIS doesn´t delete de=nothing 'and now, give it a try, it should work w3svc.Invoke("delete", Params)