Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way to use SPSecurity.RunWithElevatedPrivileges conditionally. For example, assume that i have a code block, if some condition is met i want to run this code block in SPSecurity.RunWithElevatedPrivileges, otherwise i want to run this code block without SPSecurity.RunWithElevatedPrivileges

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Put your code in a method with the VOID return (required by the delegate). Afterwards, use the if to determine your condition, and the actual method.

 //Run the MyElevatedFunctionCall function with elevated priviledges
       SPSecurity.CodeToRunElevated elevatedCall = new SPSecurity.CodeToRunElevated(MyElevatedFunctionCall);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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