views:

284

answers:

1

Hi all.

I hope everybody is doing fine.

I try to delete a virtual directory using WMi (Server Manager Class) and recreate with different values. The problem i am facing is that the virtual directory is not getting deleted. Please help.

How to check existance of a virtuual dir and the call delete?

and similarly how check whether a directory exists before adding the same again with slightly different properties.

Basically the goal was to rename a virtual directory along with renaming a website. I hope i am clear

Here is my code.

Try
  Using mgr As New ServerManager()
    Dim site As Site = mgr.Sites(DomainName)
    Dim app As Application = site.Applications("/") '.CreateElement() '("/" & VirDirName)
    Dim VirDir As VirtualDirectory = app.VirtualDirectories.CreateElement()
         For Each VirDir In app.VirtualDirectories
              If VirDir("path") = "/" & VirDirName Then
                    app.VirtualDirectories.Remove(VirDir)
                    Exit For
              End If
         Next
         mgr.CommitChanges()
  End Using
 Catch Err As Exception
      Ex = Err
      Throw New Exception(Err.Message, Ex)
 End Try
+1  A: 

Just to clarify the code above is not using WMI but Microsoft.Web.Administration (MWA).

Are you saying that your goal is to rename the site's directory or just the site name? If you change the Sitename nothing further should be required. If the goal is to keep the directory name in sync, then almost always it is the root of the site what you want to rename, so just do something like:

Using mgr As New ServerManager() 
   Dim site As Site = mgr.Sites(DomainName) 
   site.Applications("/").VirtualDirectories("/").PhysicalPath = "...Whatever new physical Path"

   mgr.CommitChanges()
End Using 
CarlosAg
Actually i wanted something else, but your solution solves the problem anyways. Thank you.
Steve Johnson