Tuesday, March 17, 2009

Running SharePoint custom code with elevated/ administrative privileges

Whenever writing a custom code(workflow / web parts / event handlers) for MOSS site, we sometimes require administrative previleges to run the custom code.


using Microsoft.SharePoint;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Code to Run with admin privileges
});

This will take care of running the code with Administrative privileges. (Administrative account) even the user does not have access to the site.

No comments: