0

I have to build a simple full trusted SharePoint Solution with a webpart. When a user clicks a button in this webpart, I want to change some data in a list, to which he has only read-only permissions. However, when I try to do it, SharePoint gives me a page with a message: "User access denied". When I try the same scenario with a user who has a write access to that list, everything works.

My question is, why does full trusted SharePoint solution does not have an access to write to a SharePoint list when the user does not and vice versa? Is there any permission setting I need to set for that solution?

I am using SSOM, something like this: https://www.tutorialspoint.com/sharepoint/sharepoint_server_object_model.htm

Thank you for your ideas.

2 Answers 2

1

Try the method "RunWithElevatedPrivileges", should work.

https://msdn.microsoft.com/library/Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges.aspx

Example:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
  //Your code here
});
2
  • very cool! thank you so much. I will try it in few hours and let you know if this works! :)
    – Pedro
    Commented Apr 5, 2018 at 10:48
  • I had to add this before running the command oSite.AllowUnsafeUpdates = true; oWeb.AllowUnsafeUpdates = true;
    – Pedro
    Commented Apr 6, 2018 at 15:30
1

Full-trust farm solutions execute without any code access security restrictions , but this doesn't mean it override the users permissions by default,

you can use SPSecurity.RunWithElevatedPrivileges method to Executes the specified actions with Full Control rights even if the user does not otherwise have Full Control.

SPSecurity.RunWithElevatedPrivileges method

3
  • very cool! thank you so much. I will try it in few hours and let you know if this works! :)
    – Pedro
    Commented Apr 5, 2018 at 10:48
  • @Pedro good , please do that :)
    – A.Saéed
    Commented Apr 5, 2018 at 10:52
  • awesome, it worked. I had to add this before I ran the command and then I turned it back off oSite.AllowUnsafeUpdates = true; oWeb.AllowUnsafeUpdates = true;
    – Pedro
    Commented Apr 6, 2018 at 15:30

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.