Quantcast
Channel: Installation and Setup
Viewing all articles
Browse latest Browse all 631

Delete Web Site and Content programmatically

$
0
0

I'm developing a Web Setup Installer Project with C#, .NET Framework 4.7 and Visual Studio 2017 Professional version 15.3.5.
I've found that I can use Microsoft.Web.Administration.Application dll in an Installer class to work with Web App created.
I know how to delete Web App from IIS on Installer's class uninstall method:

public override void Uninstall(IDictionary state)
    {
        base.Uninstall(state);

        // Do my custom uninstall actions
        string physicalPath;
        ServerManager serverManager = new ServerManager();

        Application myApp = serverManager.Sites[siteName].Applications[webAppPath];
        physicalPath = myApp.VirtualDirectories["/"].PhysicalPath;
        serverManager.Sites[siteName].Applications.Remove(myApp);

        ApplicationPool myAppPool =
            serverManager.ApplicationPools[appPoolName];
        serverManager.ApplicationPools.Remove(myAppPool);

        serverManager.CommitChanges();

        //System.IO.Directory.Delete(physicalPath, true);
    }

But this line System.IO.Directory.Delete(physicalPath, true); needs administration privilege.
Do you know if I can do Deploy -> Delete Web Site and Content like we can do in IIS?<br/>


Viewing all articles
Browse latest Browse all 631

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>