Tuesday, June 25, 2013

BeforeProperties and AfterProperties in Sharepoint Event Receivers

Many of us have used BeforeProperties and AfterProperties while working with Event Receiver, but we don't know how and when to use these properties while accessing the data/field value.

These are facts we need to consider while working with Event receiver.

1) We should not use Before properties for accessing change of value at List level.
2) Before properties are available only with Document Library


I am summarizing about BeforeProperties, AfterProperties and properties.ListItem in sharepoint event receiver context.

List:
ListBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo valueNew valueNull
ItemAddedNo valueNew valueNew value
ItemUpdatingNo valueChanged valueOriginal value
ItemUpdatedNo valueChanged valueChanged value
ItemDeletingNo valueNo valueOriginal value
ItemDeletedNo valueNo valueNull

Library:

LibraryBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo valueNo valueNull
ItemAddedNo valueNo valueNew value
ItemUpdatingOriginal valueChanged valueOriginal value
ItemUpdatedOriginal valueChanged valueChanged value
ItemDeletingNo valueNo valueOriginal value
ItemDeletedNo valueNo valueNull


Here one more scenario we need to consider before we conclude this topic.

I have one example where I need to prevent the user from entering the same value for a column.

Ex: Suppose column called Description and its initial value is "Test" and user go to the list and update the item for that column with the same value we need to prevent this. How to achieve this?

So if we observe carefully with above table then we have answer available immediately.
In the ItemUpdating Event we can check the condition like

if(properties.ListItem["Description"] != properties.AfterProperties["Description"])
{
         //Cancel the event
         properties.Cancel = true;
         properties.ErrorMessage = "The column is having same original value";
}


 

Wednesday, June 5, 2013

How to check SharePoint Version

If you are a SharePoint resource and some time you may come across any web site which looks similar to MOSS/ SharePoint 2010/2013 but you are not sure whether its a SharePoint site or not(may be they will revamp completely with CSS, master page so that no one can identify its SharePoint site or not). In that case how to check its SharePoint site or not.

Follow below steps which will show which version of SharePoint or is the site itself is not SharePoint one.

1) Open the site in IE(any of the site)

2) Click F12 which will open IE developer tool.

3) Click on Network tab






4) Click on start Capturing button
 





5) Refresh the page so that it will capture the traffic.

6) Now click on any of the URL under traffic as shown below.
ex: /_layouts/15/init.js?rev

 
7) Click on "Go to detailed View"

8) Click on Response headers and check the MicrosoftSharePointTeamServices header :

For MOSS it will show as 12.0.0.
SharePoint 2010 14.0.0.
SharePoint 2013 it will be 15.0.0