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 web part that, after insert an item in a list where the current user has the permission, need to insert an item in a list where the current user hasn't access. How can I do that?

share|improve this question
    
Maybe Gaetanu You Are doing something wrong? Try to sit in it more then 25 minutes. –  Grzegorz Z Oct 16 '12 at 14:09
add comment

1 Answer 1

You can use the RunWithElevatedPrivileges method to elevate your code and allow the user permission to the list.

SPUser currentUser = SPContext.Current.Web.CurrentUser;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
     // code to run here
   item["Editor"] = currentUser;
   item["Author"] = currentUser;
   item.Update();
});

HTH

share|improve this answer
    
I read that is not a good way to accomplish this issue and I after the update I haven't the item in the list –  Gaetanu Oct 16 '12 at 13:56
    
I'm curious, where did you read this is not a good method to use? Run a debugger and ensure the code is firing. It should work without issue. On your new items, if you want them tagged from the current user, you need to declare a user object outside of the method, then set it to the Author and Editor fields. –  David Lozzi Oct 16 '12 at 14:16
    
1  
Thanks for sharing that, I haven't come across that before. Asking my colleagues at the table, they also lean towards using SPSecurity.RunwithElevatedPrivilege. I'm going to do some more research to see what the real differences are. –  David Lozzi Oct 16 '12 at 18:34
add comment

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.