Conditional SPSecurity.RunWithElevatedPrivileges
-
10-12-2019 - |
Question
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
Solution
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);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange