SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

 
discard

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.