Retracting a WSP




Go back to index

How to retract and delete a WSP


Following code block explains how to programmatically retract a WSP solution from web applications and delete the WSP from the solution store. The method itself waits till the solution is completely retracted. Configuring the wait time will be available in future release.

      using System;
      using SPTool.Library;
      using System.Collections.ObjectModel;
 
      namespace SPTool.Test
      {
          class Program
          {
              static void Main(string[] args)
              {
                  SPTFarm farm = new SPTFarm();
                  
                  // Retract the solution
                  SPTReturn returnObj = farm.RetractSolution("SPTool.wsp");

                  // Use the below method if you need to retract from specific web applications
                  //Collection<Uri> webAppUris = new Collection<Uri>();
                  //webAppUris.Add(new Uri("http://sptool"));
                  //returnObj = farm.RetractSolution("SPTool.wsp",webAppUris);
                      
                  // Check the status of retracting the solution
                  if (returnObj.State == SPTState.Success)
                  {
                      // Delete the solution
                      returnObj = farm.DeleteSolution("SPTool.wsp");
                      
                      // Check the status of deleting the solution
                      if (returnObj.State == SPTState.Success)
                      {
                          // Solution successfully deleted
                      }
                      else
                      {
                          // Deleting solution failed
                      }
                  }
                  else
                  {
                      // Retracting solution failed                               
                  }

              }
          }
      }
      


Go back to index