Skip to main content

Posts

My surface book

Recent posts

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...

No AllowUnsafeUpdates ?

Alternative for AllowUnsafe updates if (null != SPContext.Current) { SPUserToken adminUser = SPContext.Current.Site.SystemAccount.UserToken; using (SPSite site = new SPSite(SPContext.Current.Site.ID, adminUser)) { using (SPWeb web = site.OpenWeb()) { SPUtility.ValidateFormDigest();  //Enter your code here to do Operation } } } SharePoint smoking................ Dharani

Error While Accessing SharePoint through Console

If you are trying to access the SharePoint site through console for the first time you may get the below error System.IO.FileNotFoundException was unhandled   Message=The Web application at http://win-872tgscbp72:2890 could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application. To resolve this 1) Project Properties -- > Application tab Just check target framework is .Net Framework 3.5 2)Project Properties -- > Build tab Platform target to ANY CPU or x64 By following these 2 steps it should work fine, If your still getting the error change the Debug option as shown below and last  everything   will  work fine. SharePoint smoking.......... Dharani