Elevated Privileges in SharePoint 2007

This is a quick note on incorporating ElevatedPrivileges in custom webparts, event handlers, etc.

Inside the CreateChildControls() method, register the Button Click method reference or any other event.


Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
AddHandler Button1.Click, AddressOf Button1_Click
 End Sub

Inside the Button Event, raise the ElevatedPrivileges in the following way.


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
SPSecurity.RunWithElevatedPrivileges(AddressOf MethodWithElevatedPermission)
 End Sub

Private Sub MethodWithElevatedPermission()
' Add desired business logic here
 End Sub

I have not had the chance to test this on SharePoint 2010 custom application, however I am pursuaded to think it will work for SharePoint 2010 as well providing SharePoint 2010 embraces SharePoint 2007 Object Model.

For C# reference:
http://msdn.microsoft.com/en-us/library/bb466220(v=office.12).aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s