0

Create Site Column Programmatically in SharePoint

Hi

Today I am going to explain you How to create Site column Programmatically (xml)

It should be also created through OOTB and PowerShell

What is site column

Site column is pre define site column which are reused in various content type and List, Libraries

For e.g. you can create a site column “Sample” with a Single Line of text data type . This column then can be added to any content type in your list or library.

We can achieve it two ways

Using Declarative XML

code (Feature Activation Event Receiver)

In this blog we can achieve it through xml..

Ok let`s start

Continue reading

0

CRUD Operation with REST API in SharePoint

Overview of CRUD operation with REST API in SharePoint will be explained in this article.

 

SharePoint 2013 enables you to remotely interact with SharePoint sites by using REST. By using REST API you can interact with SharePoint site from any technology which can support REST API i.e. IPhone, Android, PHP, JAVA etc..

 

Now question is what is this REST API?

Full form of REST is Representational State Transfer (REST). This is service provide in SharePoint 2013. To perform all basic operation which can be perform using CSOM or JSOM.

 

So now you will ask that what is new in REST API?

REST API has obvious benefits for mobile applications that are written in non-Microsoft platforms, such as iOS and Android devices, and it’s also a useful resource for Windows 8 apps which are written in HTML5 and JavaScript which can interact with SharePoint site through REST API.

Now come to the point how to use REST API in SharePoint?

To use REST API you need to construct a RESTful HTTP request string using OData Standard (OData = Open Data Protocol)

 

 

Construction of REST API URL

Base URL

   http://<domain>/<site url>/_api/

Retrieve the lists from a SharePoint site

   http://<domain>/<site url>/_api/web/lists

Get a particular list by specifying its ID or Title

   _api/web/lists/getByTitle('ListName')/

In REST API you need to pass address of your site then add “/_api/lists/” and all list in site will be display. You can use other REST Client to perform REST Queries.To access any Site Collection you need to pass “_api/site” and to access any site then you need to pass “_api/web


 

Get Groups in site by using REST API

_api/Web/SiteGroups/GetById(IdOfGroup)

 

Get user by user id

_api/web/getuserbyid(UserId)

 

Remove particular user from group

executor.executeAsync({
  url: "<app web url>/_api/web/sitegroups(GroupId)/users/getbyid(UserId)",
  method: "POST",
  headers: { "X-HTTP-Method": "DELETE" },
  success: successEventHandler,
  error: errorEventHandler
});

 

Get all user in Site/Web

_api/web/siteusers

 

To get all groups of site

_api/web/sitegroups

Get all items in List

_api/web/lists/getByTitle('Task')/items

 

Option for filtering and sorting data in REST API

Option Purpose
$select Specifies which fields are included in the returned data.
$filter Specifies which members of a collection, such as the items in a list, are returned.
$expand Specifies which projected fields from a joined list are returned.
$top Returns only the first n items of a collection or list.
$skip Skips the first n items of a collection or list and returns the rest.
$orderby Specifies the field that’s used to sort the data before it’s returned.

 

Examples

_api/web/lists/getByTitle('Languages')/items?$select=Title,LanguageScope,LanguageType
_api/web/lists/getByTitle('Languages')/items?$filter=LanguageScope eq 'High'

 

Note: Multiple option can be combine using “&” operator

_api/web/lists/getByTitle('Languages')/items?$select=Title&$filter=LanguageScope eq 'High'&$top=2

 

Explanation:

This will get top 2 item Title whose Scope=’High’

 


Best way to use REST Call is AJAX.

Here is simple example of REST Call with AJAX

$.ajax({
  url: "http://<site url>/_api/web/Users",
  type: "GET",
  headers: { "content-type": "application/json;odata=verbose" },
  success: successEventHandler,
  error: errorEventHandler
});

 

Create New Web using REST API

 

Note: Here Type will be “POST” because we are putting data in SharePoint. Otherwise it will generate error.


$.ajax({
  url: "http://<site url>/_api/web/webs/add",
  type: "POST",
  data: "{ 'parameters': { '__metadata': { 'type': 'SP.WebCreationInformation' },
    'Title': 'NewMyWeb', 'Url': 'MyCustomWeb', 'WebTemplate': 'STS',
    'UseSamePermissionsAsParentSite': true } }",
  headers: { 
    "X-RequestDigest": "Digest value",
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "content-length": "Body Data Length"
  },
  success: successEventHandler,
  error: errorEventHandler
});

 

Delete Web using REST API

To delete any web we need to specify url for that particular web and make sure

“X-HTTP-Method”:”DELETE” 

otherwise delete operation will not perform


$.ajax({
  url: "http://<site url>/_api/web",
  type: "POST",
  headers: { 
    "X-RequestDigest": "Digest Value",
    "X-HTTP-Method": "DELETE"
  },
  success: successEventHandler,
  error: errorEventHandler
});

 

Hope now you will get enough idea to get start with REST API in SharePoint.

Please Like and share this blog and comment if you are stuck anywhere.

Happy Coding..!!
Learn code while playing with it..!!