locked
Remove VIrtual directory with custom fodlers while uninstalling the project RRS feed

  • Question

  • User1417144093 posted

    Hi,

    while UnInstalling the web project , some of the folders like Log etc .. are remaining still, so because of this virtual directory is not able to delete , can any one help on this .. while unstalling i want to remove recpective virtual directory even though it conatins the custom folders.

    Thanks in advance,

    Hanumanth.

    Tuesday, March 17, 2009 1:05 AM

Answers

  • User372121194 posted

    Hi,

    You can try to use Custom Action to delete Metabase Node by using System.DirectoryServices while uninstalling. To do this, we need to override Uninstall method of Custom Action and add this Custom Action to Web Setup's Uninstall Custom Actions.

    For example, delete virtual directory:

    static void DeleteTree(string metabasePath)
    {
      //  metabasePath is of the form "IIS://<servername>/<path>"
      //    for example "IIS://localhost/W3SVC/1/Root/MyVDir"
      //    or "IIS://localhost/W3SVC/AppPools/MyAppPool"
      Console.WriteLine("\nDeleting {0}:", metabasePath);

      try
      {
        DirectoryEntry tree = new DirectoryEntry(metabasePath);
        tree.DeleteTree();
        tree.CommitChanges();
        Console.WriteLine(" Done.");
      }
      catch (DirectoryNotFoundException ex)
      {
        Console.WriteLine(" Done.");
      }
      catch (Exception ex)
      {
        Console.WriteLine("Failed in DeleteTree with the following exception: \n{0}", ex);
        Console.WriteLine("Could not delete metabase path {0}", metabasePath);
      }
    }

    For more information about the example, see http://msdn.microsoft.com/en-us/library/ms524896.aspx

    For the Custom Action example, see http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx

     

    I look forward to receiving your test results.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 19, 2009 5:04 AM

All replies

  • User372121194 posted

    Hi,

    You can try to use Custom Action to delete Metabase Node by using System.DirectoryServices while uninstalling. To do this, we need to override Uninstall method of Custom Action and add this Custom Action to Web Setup's Uninstall Custom Actions.

    For example, delete virtual directory:

    static void DeleteTree(string metabasePath)
    {
      //  metabasePath is of the form "IIS://<servername>/<path>"
      //    for example "IIS://localhost/W3SVC/1/Root/MyVDir"
      //    or "IIS://localhost/W3SVC/AppPools/MyAppPool"
      Console.WriteLine("\nDeleting {0}:", metabasePath);

      try
      {
        DirectoryEntry tree = new DirectoryEntry(metabasePath);
        tree.DeleteTree();
        tree.CommitChanges();
        Console.WriteLine(" Done.");
      }
      catch (DirectoryNotFoundException ex)
      {
        Console.WriteLine(" Done.");
      }
      catch (Exception ex)
      {
        Console.WriteLine("Failed in DeleteTree with the following exception: \n{0}", ex);
        Console.WriteLine("Could not delete metabase path {0}", metabasePath);
      }
    }

    For more information about the example, see http://msdn.microsoft.com/en-us/library/ms524896.aspx

    For the Custom Action example, see http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx

     

    I look forward to receiving your test results.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 19, 2009 5:04 AM
  • User1417144093 posted
    hi Thomas thanks for ur help,  as im new to .net can you tel how to override the uninstall class, kindly send the full code.
    Thursday, March 19, 2009 6:39 AM
  • User372121194 posted

    Hi,

    Thanks for your response.

    To create Custom Action, we can add Installer Class to Class Library and override Uninstall method in this Installer Class:

            public override void Uninstall(System.Collections.IDictionary savedState)
            {
                base.Uninstall(savedState);

                ///
                ///TODO: delete virtual directory
                ///
            }

     For more information, see Walkthrough: Creating a Custom Action (http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx).

     

    I look forward to receiving your test results.

    Thursday, March 19, 2009 10:23 PM