Deploying a WSP




Go back to index

How to add and deploy a WSP


Following code block explains how to programmatically add a WSP solution to solution store and deploy the solution to the web applications. The method itself waits till the solution is completely deployed. 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();
                  
                  // Add the solution
                  SPTReturn returnObj = farm.AddSolution(@"C:\Program Files\E-Infotainment\SPTool\Solution\SPTool.wsp");

                  // Check the status of adding the solution
                  if (returnObj.State == SPTState.Success)
                  {
                      // Deploy the solution to all web applications                      
                      returnObj = farm.DeploySolution("SPTool.wsp", true, false);
                      
                      // Use the below method if you need to deploy it to specific web applications
                      //Collection<Uri> webAppUris = new Collection<Uri>();
                      //webAppUris.Add(new Uri("http://sptool"));
                      //returnObj = farm.DeploySolution("SPTool.wsp", true,webAppUris,false);

                      // Check the status of deploying the solution
                      if (returnObj.State == SPTState.Success)
                      {
                          // Solution successfully deployed
                      }
                      else
                      {
                          // Deploying solution failed
                      }
                  }
                  else
                  {
                      // Adding solution failed                               
                  }

              }
          }
      }
      


Go back to index