Ways to Access Data from SharePoint 2010
In SharePoint 2010 object model, MS has introduced various new classes and namespaces to facilitate quick and easy data retrieval. In this post I we will discuss advantages and disadvantages of various methods that you might use to pull data from SharePoint 2010. Lets Begin.
1. Client OM - The Client Object Model (OM) is a new programming interface for SharePoint 2010 where code runs on a user’s client machine against a local object model and interacts with data on the SharePoint Server.
Used When - When you need to access sharePoint data from a remote application for e.g. need to access data from WPF or Windows application using client OM like javascript.
Advantages :
. You can execute or line up all the server tasks in one SharePoint server server call.
. It returns you Json object that you can bind to a client side object.
. Used when a SharePoint List\site object is needs to be returned.
. Anything can be accessed down to site collection level.
Disadvantages :
. Can only use relative url of sharepoint site. You cannot do cross-site scripting.
. Not good for accessing Relationship items. For e.g. accessing Parent items and then its related child items.
2. Server OM - Access data using SharePoint 2010 API's
Used when - When you need to access data from an application which is on the SharePoint Server itself. For e.g. Retrieving data in a Custom webpart.
Advantages :
. Can use CAML query or LINQ to return data and bind it with asp.net controls.
. Get site\List object for further query.
Disadvantages :
. Wont work on Computer not having SharePoint installed.
. Cannot use API's in a client side application.
2. REST API's - REST (Representational State transfer) is a protocol (powered by ADO.NET services) which is used for getting data out of sharepoint via Url.
The syntax of the url is
http://SPServer/_vti/bin/ListData.svc/{Entity}[({identifier})]/[{Property}]
In above statement -
ListData.svc - This is a wcf srevices that follows REST protocol.
Entity - Is SharePoint List name.
Identifier - Can be Id of the List item.
Property - Column of the Item.
You can also get Filtered data via Url
For e.g. below url will get data from Cities list where City = 'NJ'
/_vti/_bin/ListData.svc/{Entity}?filter=Cities/ City eq 'NJ'
Advantages :
. You can quickly access data from sharepoint even when you are not in the sharepoint context.
. It can do cross site scripting Supported by IE 8.
. Good for accessing Relational data like Parent and child since the result is an xml with all the parent child nodes.
Disadvantages :
. Does not return an object for Site\List.
4. LINQ to SharePoint - LINQ is the Entity based programming on the server. It is mostly used for performing LINQ queries on SharePoint list\libraries.
Used When - When you need get data from a rich relational structure or need to perform join queries on lists, even when they are not related.
Advantages :
. Fast data retrival.
. Can write SQL like queries.
. Returns xml output, thus can be used to reterive relational (Parent-child) data.
Disadvantages :
. Cannot use LINQ in Client OM. It runs on server only.
. It is converts the LINQ query into CAML therefore, adding an extra step for data retrieval.
1. Client OM - The Client Object Model (OM) is a new programming interface for SharePoint 2010 where code runs on a user’s client machine against a local object model and interacts with data on the SharePoint Server.
Used When - When you need to access sharePoint data from a remote application for e.g. need to access data from WPF or Windows application using client OM like javascript.
Advantages :
. You can execute or line up all the server tasks in one SharePoint server server call.
. It returns you Json object that you can bind to a client side object.
. Used when a SharePoint List\site object is needs to be returned.
. Anything can be accessed down to site collection level.
Disadvantages :
. Can only use relative url of sharepoint site. You cannot do cross-site scripting.
. Not good for accessing Relationship items. For e.g. accessing Parent items and then its related child items.
2. Server OM - Access data using SharePoint 2010 API's
Used when - When you need to access data from an application which is on the SharePoint Server itself. For e.g. Retrieving data in a Custom webpart.
Advantages :
. Can use CAML query or LINQ to return data and bind it with asp.net controls.
. Get site\List object for further query.
Disadvantages :
. Wont work on Computer not having SharePoint installed.
. Cannot use API's in a client side application.
2. REST API's - REST (Representational State transfer) is a protocol (powered by ADO.NET services) which is used for getting data out of sharepoint via Url.
The syntax of the url is
http://SPServer/_vti/bin/ListData.svc/{Entity}[({identifier})]/[{Property}]
In above statement -
ListData.svc - This is a wcf srevices that follows REST protocol.
Entity - Is SharePoint List name.
Identifier - Can be Id of the List item.
Property - Column of the Item.
You can also get Filtered data via Url
For e.g. below url will get data from Cities list where City = 'NJ'
/_vti/_bin/ListData.svc/{Entity}?filter=Cities/ City eq 'NJ'
Advantages :
. You can quickly access data from sharepoint even when you are not in the sharepoint context.
. It can do cross site scripting Supported by IE 8.
. Good for accessing Relational data like Parent and child since the result is an xml with all the parent child nodes.
Disadvantages :
. Does not return an object for Site\List.
4. LINQ to SharePoint - LINQ is the Entity based programming on the server. It is mostly used for performing LINQ queries on SharePoint list\libraries.
Used When - When you need get data from a rich relational structure or need to perform join queries on lists, even when they are not related.
Advantages :
. Fast data retrival.
. Can write SQL like queries.
. Returns xml output, thus can be used to reterive relational (Parent-child) data.
Disadvantages :
. Cannot use LINQ in Client OM. It runs on server only.
. It is converts the LINQ query into CAML therefore, adding an extra step for data retrieval.
0 comments:
Post a Comment