RemoveApplication(IISHandler handler, string appName, string siteName) { if (appName.Equals("/")) { Console.WriteLine(appName + " cannot be removed safely. It is the site default. Removing would corrupt website."); return; } String[] paths = null; if (PathHelper.ContainsWildcard(appName)) { Site site = handler.GetSiteByName(siteName); if (site == null) { Console.WriteLine("Site " + siteName + " does not exist."); return; } paths = PathHelper.ExpandWildcardDirectories(appName); List <Application> apps = new List <Application>(site.Applications.Where(p => paths.Contains(p.VirtualDirectories["/"].PhysicalPath))); foreach (var app in apps) { Console.WriteLine("Removing app " + app); try { handler.RemoveApplicationNonCommit(site, app); } catch (Exception e) { Console.WriteLine(e.Message); } } handler.CommitChanges(); return; } try { handler.RemoveApplication(siteName, appName); } catch (Exception e) { Console.WriteLine(e.Message); } }