SharePoint Impersonation

SharePoint code runs in the context the user activates certain code. When this user doesn't have sufficient priviliges to update an item, you run in a security exception.

Use RunWithElevatedPrivileges in order to run code as administrator privileges.


SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(this.Site.Url))
{
using (SPWeb web = site.OpenWeb(this.Web.ID))
{
web.AllowUnsafeUpdates = true;

//ACTIONS

web.AllowUnsafeUpdates = false;
}
}
});

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)