0

i need help wit this I want user to edit list items (insert) without having a permission of edit for that list in c# how can i do that?

1
  • What version of SharePoint are you targeting? Commented Oct 15, 2018 at 14:19

3 Answers 3

1

Try using SystemAccount System Account.

SPUserToken sysToken = properties.Site.SystemAccount.UserToken;
using (SPSite elevatedSite = new SPSite(properties.Site.ID, sysToken))
{
   using (SPWeb elevateWeb = elevatedSite.OpenWeb())
   { 
       //your code here...
   }
}

BOUCHAALA AHMED

1
  • You are welcome Shams Commented Oct 16, 2018 at 10:03
1

You can use SPSecurity.RunWithElevatedPrivileges, here is an exemple :

Guid siteId = SPContext.Current.Site.ID;
Guid webId = SPContext.Current.Web.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(siteId))
    {
        using (SPWeb web = site.OpenWeb(webId))
        {
            // Your code here
        }
    }
});

BOUCHAALA AHMED

1
  • every time i got this Sorry, this site hasn't been shared with you. Commented Oct 15, 2018 at 14:46
0

In C#, I believe you can use impersonation to add list items in sharepoint list without having permission on list.

For more information, click here.

Impersonation in SP 2010, here.

Using SPTokens for impersonation. For more info here.

Please upvote if this answer helped you in any way.

4
  • in SP2013?? how can I Commented Oct 15, 2018 at 13:22
  • Use RunWithElevatedPrivileges() in C#, see first link for more information clarification. Commented Oct 15, 2018 at 14:01
  • every time i got this Sorry, this site hasn't been shared with you. Commented Oct 15, 2018 at 14:45
  • Great. Please upvote if this answer helped you in any way. Commented Oct 16, 2018 at 11:54

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.