2

enter image description here

As shown in this image, I am unable to create a SPUserToken or run the SPSecurity.RunWithElevatedPrivileges() delegate in order to elevate the current user for the purpose of managing list item permissions. Is there a different Microsoft.Sharepoint library that I should be using, or something silly I'm doing wrong?

2 Answers 2

2

My guess would be that you've selected the default of creating a "Sandboxed solution" in which SPUserToken and SPSecurity isn't supported.

If you need to run elevated, then your solution should be a Farm solution (or and app with AllowAppOnlyPolicy).

Click the SharePoint project node ('DOCApp') and check the properties (F4): enter image description here

This should be set to False to allow running elevated

1
  • 1
    Thank you for your answer. Changed to False and now it's working great.
    – Ryan
    Commented May 28, 2013 at 13:55
0

Have you tried with complete code for RunWithElevatedPrivileges or SPUserToken code? It seems that you have correctly referred the Microsoft.SharePoint (in Microsoft.SharePoint.dll) assembly in source code.

Try an example below with RunWithElevatedPrivileges:

SPSecurity.RunWithElevatedPrivileges(delegate(){  


         using (SPSite newSite = new SPSite(properties.WebUrl)) {  

            using (SPWeb newWeb = newSite.OpenWeb()){
               //some logic

          }// End of using for SPWeb

       }// End of Using for SPSite

   });//End of SPSecurity.RunWithElevatedPrivileges 

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.