1

I'm currently working on my SharePoint Remote Administration Service. 1 of the functions is to install/remove/upgrade solution.

Since the documentation is very short on MSDN, i wonder if the following is sufficient:

if (actionToTake == "REPLACE")
        {
            SPSolution solution = GetSolutionByName(nicename);
            if (solution != null)
            {
                if (solution.DeployedWebApplications.Count > 0)
                {
                    StateHandler.WriteValueToRegistry("30");
                    solution.Upgrade(fullpath);

                    Thread.Sleep(100);


                    while (solution.JobExists)
                    {
                        Thread.Sleep(100);
                    }

                    solution.Provision();

                    while (solution.JobExists)
                    {
                        Thread.Sleep(100);
                    }
                    StateHandler.WriteValueToRegistry("100");
                }
            }

The Code just do a provision at the end, no update(). Same for new install and remove I wonder if a call to update() is also required or any other actions. Thanks!

1

dont quite understand what your doing in code! but in my codeplex project i have a method that deploys all wsp's to a given spwebapplication!

    private void executeSolution(bool add)
    {
        try
        {                        
            Collection<SPWebApplication> webapps = new Collection<SPWebApplication>();
            SPWebApplication webapp = SPWebApplication.Lookup(new Uri(url));
            webapps.Add(webapp);

            SPSolutionCollection spSC = SPFarm.Local.Solutions;
            foreach (SPSolution spSolution in spSC)
            {

                if (spSolution.ContainsWebApplicationResource)
                {
                    if (add == true)
                    {
                        //deploy
                        spSolution.Deploy(DateTime.Now, true, webapps, true);
                        //logging
                        txtLogging.Text += spSolution.DisplayName + " to " + url + Environment.NewLine;
                    }
                    else
                    {
                        foreach (SPWebApplication weba in spSolution.DeployedWebApplications)
                        {
                            if (weba.Name == webapps[0].Name)
                            {
                                //retract
                                spSolution.Retract(DateTime.Now, webapps);
                                //logging
                                txtdebug.Text += spSolution.DisplayName + " removed from " + url + Environment.NewLine;
                                break;
                            }
                        }

                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        this.btnDeploy.Enabled = true;
        MessageBox.Show("Done, Please give it time for all the webparts that have been deployed to deploy." + Environment.NewLine + "Depending on the ammount of webparts deployed will determin how long it will take." + Environment.NewLine + "You will notice your web app performe an iisreset for each deployed webpart");
    }

lol you need to change the code tho so that it doesnt loop though each and every wsp, rather it just uses the only one wsp!

to have the full code its on codeplex at:

http://deployretractallwsp.codeplex.com/SourceControl/latest#bulkDeploymentv2/bulkDeployment/bulkDeployment/frmBulkDeploy.cs

was done in a rush about a year ago but it does the job! also it was done for 2007 but should be the same for 2010, code adds and retracts to a spwebapplication

also not that:

Performing a Replacement upgrade programmatically is the same as programmatically retracting the old solution and then adding and deploying the new version. To perform an Update type of upgrade programmatically, your code calls one of the overloads of the SPSolution.Upgrade() method. For this method to run, a solution must be present in the solution store. It may or may not already be deployed.

If the solution is not deployed, call the SPSolution.Upgrade(String) method to update the solution in the solution store.

If the solution is deployed, call the SPSolution.Upgrade(String, DateTime) method to start the timer job for upgrade. In either case, a backup of the old version of the solution is created.

http://msdn.microsoft.com/en-us/library/aa543659(v=office.14).aspx

  • Thanks for your Quick Reply. one thing i notice is that you don't do a provision() in your methods or update(). Now i'm not sure if this is required or not. Is your code tested against a multi server farm? Before this part of the code, foldername, solution name are retrieved by a config file. Then it looks for the action to take, in this case REPLACE wich means the solution is installed before and just need update. I think i will have a deeper look into your code. – JoeriDC Oct 3 '13 at 11:29
  • no need to update! or provision, it has been tested in a multi server farm, i made it when i was testing at work and got annoyed when i wanted to add wsp to multiple webapps, manually would of taken ages so i made this quick app! – Ali Jafer Oct 3 '13 at 15:22
  • no probs happy to help! – Ali Jafer Oct 4 '13 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.