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?
3 Answers
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
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
-
every time i got this Sorry, this site hasn't been shared with you. Commented Oct 15, 2018 at 14:46
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.
-
-
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