Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question

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 = ...
SPSecurity.RunWithElevatedPrivileges(
    delegate
    {
        using(SPSite secSite = new SPSite(webUrl)) {
            using(SPWeb secWeb = secSite.OpenWeb()){
                // Do Stuff
            }
        }
    });
share|improve this answer
    
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). –  Pedro Jacinto Aug 31 '11 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 '11 at 14:30

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.