Tuesday, May 4, 2010

What is SharePoint Out of the Box, ghosting/unghosting, page customizations and event handlers?

Hi all, 

What SharePoint provides out-of-the-box? 
Before we discuss SharePoint's OOTB features, I strongly suggest you read a compelling blog from Bjørn Furuknap for whom SharePoint OOTB features do not make sense and counter response from Bil Simser who thinks SharePoint shines because for OOTB features. 


SharePoint OOTB:

Basically, SharePoint's OOTB features includes implementations of standard pages, forms, workflows, page layouts, site templates, site definitions, list templates, list instances, ECM, blogs, wikis, create new lists and sites, create new views etc that ships with the SharePoint installations. The no code and special tools are required and only thing you need is your browser. In few of the implementations, OOTB features would suffice provided company does need high level of customization.   

SharePoint customizations:
As we know that SharePoint 2007 is web-file system. It has particular folder structure, it has files and on top of it, it has site model and an associated API. In the hierarchy, we have lists, folder etc. Consider a case we create a new announcement list. Now, this list is in file system (Ghostable) and if create a new entry in this list, that entry will be stored into content database. 



Ghosting:
When a SharePoint list is created it uses the files in the 12 hive (file system) to dynamically create all the information in the database to create the actual list. Therefore, Some of the information it stores in the database is just references to files on the server (in the 12 hive). This way our SharePoint lists will have references to our custom files in the servers 12 hive and will use those custom files to create the list, as well as keep the references to these custom files. Keeping these references around is a concept call ghosting


The same concept applies for the a "new" site. When you create a new site, SharePoint doesn't really copy the pages for that site— default.aspx and so on—into a new database table or directory. These files exist once and only once on each of the front end Web servers. Instead, SharePoint creates a reference to those files in the database tables that define the new site.

Benefits of Ghosting:


i) Saves space:
If you have a thousand sites, rather than having a thousand copies of a file you still have only one.

ii) Performance:
Instead of having to load and cache a thousand pages from the database, the server needs to cache only one copy from the file system, which can improve performance by freeing cache memory for other purposes. Loading the file from the Web server's local file system improves performance by eliminating the overhead of the database call and the network traffic to the database.Moreover, the pages are compiled and therefore far better performance.



iii) Security:
As the pages are complied and saved in 12 hive, it gives better security as well. Page loading is done by ASP.NET run time and pages can have in-line code. 



iv) Consistent page layouts


Unghosting:
Now, we if want to have additional columns in the announcement or for that matter changing anything in SharePoint UI/SHarePoint Designer then we actually  un-ghost the list/site. This basically means you are losing the references to the 12 hive and it makes a copy of everything directly in the databaseWhole page must be stored in the database

Benefits of unghosting:  
i)  Provides scalability but impact performance and Security
ii)   Support user customization. 
iii)  Users can customize and there is NO need to developer.


Disadvantages
i) Impact performance and Security
ii) Unghosting lets users customize their own sites without impacting other users who might be using the same file. Unfortunately however, unghosting also has a negative performance impact, and makes global changes, such as applying corporate branding to the entire collection of sites far more difficult.



Ghostbale (Standard Pages, Uncustomized state) Unghostbale (Customized Pages, Customized state)
1. Page loaded from the FILE SYSTEMPage laoaded from the CONTENT DATABASE
2. Loading is done by "ASP.NET" run-time i.e. page is compiledLoading is done by "Safe mode parser"
3. Through VS.NETThrough SharePoint UI or SharePoint Designer
4. Pages are uncustomized state Pages are customized state 
5. Pages allows to have in-line code WSS refuses to process it . Customized pages run in safe mode and cannot have  in-line script.



SharePoint's concept of page customization:
In SharePoint we can have two kind of pages: 
1) Standard pages >> Stored in >> FILE SYSTEM (12 hive) -- with in-line code. (SharePoint OOTB functionalities)
2) Customized pages >> Stored in >> CONTENT DATABASE (SharePoint database) -- no in-line code 


But we need some kind of mechanism to check whether page is a standard page or a customized page. And here comes virtual path provider. VPP checks if the page is a standard page, process it (ASP.NET run time) and put it in the file system (12 hive). Furthermore, if the page is a customized page, VPP process it and passes the same to the ASP.NET runtimes


For an illustrations, check this link

What is a custom event handler? (Check out Brian Wilson's 3 part series on event handlers)
A custom event handler is a .Net assembly that contains the additional business logic you need to run when the event occurs in SharePoint. For an instance, lets again consider that we don't want to delete any announcements, or do some kind of validation such a users can not enter past date, or kick an workflow or push few items of announcements to some custom list. All these cases can be done through SharePoint's event handlers.


SharePoint 2007 event handlers come with immense power but they should be dealt with caution as it has some limitations as well. 


In SharePoint 2007 we have 3 types of events: 
1) Site Level: (SPWebEventReceiver)
SiteDeleted, (NO SiteAdded)

SiteDeleting, (NO SiteAdding)
WebDeleted,  
WebDeleting, (NO WebAdding)
WebMoved,
WebMoving


Note: 
Events such as SiteAdded, SiteAdding and WebAdding are not there in SharePoint 2007 but through Feature and more specifically we can use "FeatureActivated" to creates sites. 


2) List Level: (SPListEventReceiver)
FieldAdded, 

FieldAdding, 
FieldDeleted, 
FieldDeleting, 
FieldUpdated, 
FieldUpdating

Note: 

Events such as ListAdding, ListAdded, ListDeleting and ListDeleting are not there in 2007.

3)  List Item Level  (SPItemEventReceiver)
ItemAdding, 
ItemAdded, 
ItemDeleting, 
ItemDeleted, 
ItemUpdating, 
ItemUpdated etc.


Asynchronous vs Synchronous Events:
There are 2 types event operations for event handler.
i) Asynchronous (e.g. ItemAdded - "-ed" event): Asynchronous after the event that occurs after a new item has been added to its containing object.  
>> Its an post event i.e. an event has already occurred.
>> It DOES NOT block the exceution of SharePoint. 
>> We CAN NOT cancel the event because its already triggered. 

ii) Synchronous (e.g. ItemAdding - "-ing" event): 
 Synchronous before event that occurs when a new item is added to its containing object.
>> It happens before the event. 
>> BLOCKS the flow of CODE EXECUTION execution until your event handler completes.
>>  We CAN cancel the event. Please note that if we cancel an event then "-ed" will not triggered. 

In next blog, I will talk about new and improved events in SharePoint 2010. 

Cheers, 
--aaroh 


References: 
Event handlers Part 1, Part 2 and Part 3
Virtual Path Provider
Site Definitions


No comments:

How to display Sharegate administrative dynamic reports via Power BI on SharePoint Online

After working in the SharePoint domain for a couple of years as SharePoint consultant , I am fortunate enough to help customers from man...