Skip to main content

Posts

Showing posts from 2012

Getting SPContext in Event Receiver

 public class EventReceiver1 : SPItemEventReceiver {         SPContext current ;         public EventReceiver1()         {             current = SPContext.Current;         }         ///         /// An item is being added.         ///         public override void ItemAdding(SPItemEventProperties properties)         {             base.ItemAdding(properties);                         }         } } Now we can use current variable to get the SPcontext.

How to check the Checkout and checkin of List Items in Event Receivers

To check is the List Item has been checkout or checkin the below code snippet will help. If  vti_sourcecontrolcheckedoutby of AfterProperties is null and  vti_sourcecontrolcheckedoutby of  BeforeProperties   is NOT null then the event is caused by Checkin. if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null  && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)  {      // event is fired by check-in.  }  else  {      // events  fired    other than check-in .  } Note : Better to use EventFiringEnabled=false at the starting point of the function in the event receiver (Item updating,Item Adding etc....) and at last, make to true. EventFiringEnabled=true.   Which avoids unnecessary event firing of List items Sharepoint smoking.......... Dharani CM

The SPPersistedObject, XXXXXXXXXXX, could not be updated because the current user is not a Farm Administrator

"The SPPersistedObject, XXXXXXXXXXX, could not be updated because the current user is not a Farm Administrator" craziness in Sharepoint 2010 solution  # DESCRIPTION: sets an option on content web service that allows updating of SP Administration objects such as SPJobDefinition from content web applications function Set-RemoteAdministratorAccessDenied-False() { # load sharepoint api libs [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null   # get content web service  $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService   # turn off remote administration security  $contentService.RemoteAdministratorAccessDenied = $false   # update the web service  $contentService.Update()   } Set-RemoteAdministratorAccessDenied-False Copy the ab...