R – SPFarm.Local.Solutions.Add – Exception – “Access Denied”


Here is my code snippet:

    SPSolution newSolution = SPFarm.Local.Solutions.Add(@fullPath);                            

The stacktrace and innerexception give no further clues. The Exception.Source says Microsoft.SharePoint.

SPFarm.Local.CurrentUserIsAdministrator() returns TRUE for the userid.

The userid is in the Farm Administrators group.

Any ideas?


I have changed my code to the following and still get the Access Denied error:

private void AddSolution()
   SPSolution newSolution = SPFarm.Local.Solutions.Add(@fullPath);

SPSecurity.CodeToRunElevated elevatedAddSolution = new SPSecurity.CodeToRunElevated(AddSolution);

Best Solution

Your main problem might just be that you are not DBO of a sharepoint database (_Config if I'm not wrong). Adding a solution to a farm is something that require more rights than just access to the farm.

Be sure that the user running this is Farm Administrator and DBO of the proper database.

If you still have problem... try running

stsadm -o addsolution -filename "myWsp.wsp"

If you have the proper right, it will give you the proper error.

Related Question