3

I am trying to find a way how to update a SharePoint solution programmatically with C#. (I already know how to do this with the powershell command Update-SPSolution).

I have tried using this code but it doesn't work:

SPSolution sol = SPFarm.Local.Solutions[name]; //name = mytest.wsp
sol.Upgrade(filePath); //C:\mytest.wsp

Can anyone provide some guidance?

4
  • 1
    How is it not working? What is your Farm topology? (Number of front ends etc.) If it is a multi front-end farm try to use the Upgrade overload with a DateTime parameter to schedule a TimerJob, this will execute on all Web servicers. msdn.microsoft.com/en-us/library/… Commented Jul 4, 2013 at 10:25
  • what do you mean by "it doesn't work" you must get some kind of error, try using ULS Viewer to capture error if nothing comes up in event receiver Commented Jul 4, 2013 at 13:29
  • At the moment it is a Dev-Server with all components (MSSQL, Front-End) on one system.
    – AHO
    Commented Jul 8, 2013 at 7:17
  • "It doesn't work" means that nothing happens :-(
    – AHO
    Commented Jul 8, 2013 at 7:19

1 Answer 1

1

You are using the correct code (see http://msdn.microsoft.com/en-us/library/office/ms455619.aspx). When I do this, I usually specify DateTime.Now for the second parameter. This code schedules a deployment job the same way the Update-SPSolution Cmdlet does.

What I would suggest is to run this code and then immediately refresh the Farm Solutions page to see if there is a change in status. Additionally you could use this PowerShell to see if a deployment job exists:

Get-SPTimerJob | Where-Object { $_.Name -Match "solution-deploy" }

Additionally you can check the solution itself for an existing job:

(Get-SPSolution solution.wsp).JobExists

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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