I have a Tasks List and I need to create a Web Part to display one view of that list (with a functionality similar to a List View Web Part: item viewing, editing, sorting, filtering, etc).

However, some of the users that use this web part cannot have Write-Access to this list neither to any of its individual items. (This is mostly due to the fact that the tasks are generated by an external tool which I do not control). However, this users still must be able to see the tasks that are assigned to them, and they must be able to edit them, via my Web Part.

Is there any way for me to bypass the security settings of the list, in a Web Part, (perhaps through impersonation) in order to achieve this ?

1 Answer 1


Yes. It's called RunWithElevatedPrivileges. Code in the following delegate will run as the application pool account for your web application - so it should have full rights on the list you're dealing with.

string webUrl = ...
        using(SPSite secSite = new SPSite(webUrl)) {
            using(SPWeb secWeb = secSite.OpenWeb()){
                // Do Stuff
  • Andy, I already know how to run code with elevated privileges. My question is how can I use that code with a ListView Web Part (or another custom/OOTB web part with similar functionality). Aug 31, 2011 at 13:13
  • Well, it isn't going to work in a ListView web part. You will have to use the above technique within your own custom web part. This does mean developing your own custom web part. Simply use code like this within the appropriate postback event within that web part.
    – Andy Burns
    Aug 31, 2011 at 14: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.