This should do the trick:
using (ServerManager serverManager = new ServerManager()) { Site site = serverManager.Sites["Default Web Site"]; Application application = site.Applications["/MyApplication"]; site.Applications.Remove(application); serverManager.CommitChanges(); }
The code assumes that you are /MyApplication application from the root of the Default Web Site (IIS number 1).
source share