Monday 2 May 2016

Node JS with SharePoint


What is Node JS and why?

Node JS is a java script based web development platform, where we can develop and host Web applications and Web Services. 

Let’s assume a scenario where we need to access SharePoint resources (list/library data) on mobile app or some other web application. The first thing comes to our mind is a web service.  Now we have two options to implement a web service:
1. WCF RESTful Service in C# and
2. NODE JS Web API.
The reasons to choose Node JS web service over WCF service are:
1. Open source
2. Lightning Fast Speed
3. JavaScript based
4. Comparatively faster than WCF
5. Easy to Unit Test

Prerequisites

  1. Node JS – Download and Install latest version of Node JS from here. 
  2.  Custom packages from GitHub – Download and install node packages as and when required. The cmdlets to install packages are explained in “Install Node packages” section. 
  3.  Visual studio/any other IDE

Supports only Basic or NTLM Authentication of SharePoint

To communicate with SharePoint, we are going to use a node package HTTPNTLM. It supports only NTLM authentication mode of SharePoint. If your SharePoint site supports claims based authentication, we may achieve it using a node package called request. ButI amnot going to explain it here.

Install Node Packages

Node packages can be installed using node console which will be available after installation of Node JS. Below are the packages that we need to install.

httpntlm

httpntlm package is used to communicate with SharePoint REST APIs. We just need to pass the credentials
$ npm install httpntlm --save

express

Express is a Node JS’s web application framework that provides a robust set of features for mobile and web applications
$ npm install express –save

cors

cors package allows a Web API to accept cross domain requests.
$ npm install cors –save

xml2js

Used to convert xml data into JSON format
$ npm install xml2js –save

deasync

Used to make synchronous calls to java script functions
$ npm install deasync –save

What is Express App

Express is a most popular web application framework in Node JS just like MVC in .NET.  If you are using Visual Studio, download a project template for Node JS form here. Create a new project of type ‘Basic Node.Js Express 4 Application’.



Replace the code in app.js with below code snippet.
If you are not using Visual Studio, create a JS file namedapp.js and put the below code snippet:

“use strict”
var express =require('express');
var app =express();
varroutes =require('./Routes')(app); //to be added in next step
app.listen(4444); // app.listen(<Port no>)

module.exports = app;

Routes

Routes are the application endpoints which redirects to specific web service depending upon the Request type (GET/POST) and URI.  Create a folder named Routes and add a file named index.js. Put below code: 

“use strict”
module.exports= function(app) {
varservices= require ('../Services');
varcors = require ('cors');
app.use(cors());
  //Services Routes 
app.get('/_api/getAllEmployees',cors(),Services.getAllItems);    
// app.post ('/_api/addEmployee',cors(),Services.addItem);  
}
Observe the above code snippet and find the routes.
Routes: '/_api/getAllEmployees' and /_api/addEmployee

Services

Now it’s time to access SharePoint resources using REST API. Let’s expand the above codeadd definition for Services.getAllItems. Add a new folder named Services and add a JS file named index.js and put below code in it:


“use strict”
var httpntlm = require('httpntlm');
var parseString = require('xml2js').parseString;
var deasync = require('deasync');
var siteURL = "http://<SiteCollectionName>", domainName = "<domain name>";
 
//1.Get All Employee Service 
exports.getAllItems = function (req, res) {
var httpResponse = { "statusCode": 500, result: undefined };
var url = siteURL + "/_api/web/lists/getByTitle('<ListName>')/items";
var headers = { "Accept": "application/json;odata=verbose", 
                "content-type": "application/json;odata=verbose;"
         };
httpntlm.get({
                url: url,
                contentType: 'application/json;odata=verbose',
                username: '<MyUsername>',
                password: '<MyPassword>',
                domain: '<DomainName>',
                workstation: '',
                headers:headers},
         function success(error, response) {
                 httpResponse.result = JSON.parse(response.body);                     
                 res.send(httpResponse);
            })//End of get
};//End of getAllItems
I am not writing the Code for post method here, that will allow you to get some hands-on experience on node JS.  :)

Run The Web API

You can run the web api using a cmdlet node as
$ node app.js
To test if it’s functioning or not, put the URL in browser and check the response:

 
http://<ServerName>:4444/_api/getAllEmployees

Summary

Node JS is a web hosting platform for Web sites and Web Services. Follow the steps as mentioned in this post and access the required SharePoint resources.
Any questions, comments and suggestions are most welcome! Have a great day ahead!

Saturday 2 April 2016

TOP 50 SharePoint Interview Questions


Hello guys! It’s been a long time I haven’t posted anything. So I am here with ‘TOP 50 SharePoint Interview Questions’ that will be asked in any SharePoint interview. These questions are divided into section and are applicable to all SharePoint developers with an experience ranging from 0-5 years.
The most important section among these would be the Scenario Based Questions which you may not find anywhere. Try to answer these questions. You can use comment box for that. You can Specify Question number and write the answer. I will be publishing the answers after some time. Have fun !

App Model (add-ins in Sharepoint)

Q1. What is Host Web and App web?
Q2. How to create app domain and app catalog?
Q3. Where the apps get deployed in SharePoint?
Q4. How provider hosted apps communicate with SharePoint site?
Q5. What is the major difference between Sandbox Solutions, Farm Solutions and Apps?
Q6. What is oAuth and ODATA?
Q7. What are the features that we cannot implement using app model?
Q8. What is the use of App.manifest file?
Q9. What are the different ways of hosting an app?
Q10. Can we perform CRUD operations on list items in app web? How?

Client Object Model

Q11. What is the difference between
    1. Load() and LoadQuery()?
    2. Load() and ExecuteQuery()?
    3. ExecuteQuery() and ExecuteQuery Async()?
    4. item.update() and item.systemupdate()?
Q12. What are the js files required to be loaded on a page for Java Script Object Model?
Q13. Can we execute a code with elevated permissions in .net managed COM?
Q14. What is request digest and its use?
Q.15 Write down an ajax block to update a list item containing a column of type People [Multiple select]?
Q16. What is SP.RequestExecutor?

REST API

Q17. What is the limit to retrieve no of items from list? Is there any way to retrieve more than 5000 items from list?
Q18. Write down the ajax block to insert an item into SharePoint list.
Q19. What are the scenarios where you will prefer REST api over JSOM?
Q20. How does REST call works in SP2013?
Q21. Why do we call it as REST api instead of simple web service?
Q22. How can we make sure that multiple REST service calls get executed in sequential order? What are the different ways of doing it?
Q23. How can we use REST service to retrieve search results from SharePoint?
Q24. Can we elevate privileges to get access to resources using REST api?

General

Q25. How the request is processed by IIS for SharePoint site and ASP.NET web site?
Q26. Explain Page life cycle in ASP.NET?
Q27. What is CLR? What are the features of CLR?
Q28. What is the default limit of lookup columns in a view? How can we increase the limit? What will be impact?
Q29. What is claims based authentication? Advantages over other authentication methods?
Q30. What are zones? How can we achieve single sign-on for different sites in an organization?
Q31. What are ContentDB and ConfigDB? Can we have different contentDB for different site collection?
Q32. What is Shredded storage? What if versioning is disabled?
Q33. How to design a master page in SP2013?
Q34. What are display templates in SP2013? How to modify the header of the search results? How to modify individual results?
Q35. What are search verticals in SP2013?
Q36. What are the differences between SP2010 Enterprise and SP2013 Search?
Q37. What are crawled properties and managed properties?
Q38. What are different types of crawling mechanism provided by SP2013? What is the difference between Incremental and Continuous crawl?
Q39. How can we show the contents of SharePoint On premises site on SharePoint Online search results?
Q40. What are callout popup in SharePoint 2013? How can we create custom call out popup?

Scenario Based Questions

Q41. A root site collection has a list named Contacts. How would you show all items of this list on a sub site using OOB features of SharePoint?
Q42. There are two lists say Departments and Employees. End user should be able to fill the details in both the lists from a single place, how would you achieve this? What are the different approaches and which one would you prefer and why?
Q43. A company has two SharePoint web sites, a) On Premises and b) Office 365. There is a requirement that contents of On Premises site should be searchable on Office 365 site. Is it possible? If yes then how?
Q44. A SharePoint on premises site has two lists say Employees and Departments.
Employees
EmployeeName Single Line of Text
Salary Number
Address Single Line of Text
DOJ Date and Time
DeptId Lookup










Departments
DeptId Number
Department Name Single Line of Text

On deletion of a record from Departments list, all the records with respective DeptId should be deleted.
  1. Can we achieve this OOB way?
  2. What will you choose between Workflow and Event receiver and why?
  3. What if these lists are on SharePoint online site and user has only READ permission on both the lists?
Q45. A company has SharePoint online site and they want to showcase their line of business data from SQL Server to SharePoint site. What are the different approaches? Which one will you choose? and why?
Q46. There are three different Companies say Company A, Company B and Company C. They have their own SharePoint2013 on premises portals.
Company A acquires Company B and Company C. Company A wants to have all the sites hosted on their own domain and accessible by all the users.
What are all the steps in sequence that you need to perform?
Q47. Consider the scenario in Q.6, What if all these sites are hosted on SharePoint online?
Q48. A company has a SharePoint 2013 on premises site which is accessible only within the organizational network. They decided to allow the site to be accessed externally by users from same organization from any network. How it can be achieved?
Q49. SharePoint2013 on premises web application has 50 site collections. All these site collections need to have a custom content type say EmployeeContentType. How will you achieve this with minimum development efforts and flexibility of modifying content type?
Q50. There is a requirement of adding a custom link to site settings page. Can we achieve this is SharePoint On premises? If yes then how? Is it possible with SharePoint online?

Friday 8 January 2016

BCS with SharePoint Online

Introduction

Business Connectivity Services (BCS) is a feature of SharePoint which allows to connect to external data sources and perform CRUD (Create Read Update Delete) operations. The data sources can be one of the following:
  • SQL Server
  • WCF Service
  • .NET Type
In this blog I will walk you through the detailed steps involved in implementation of BCS in SharePoint Online with WCF service as a data source. Below are the major steps required for implementation:
  • Implementation of WCF REST Web Service
  • Web Service integration with SharePoint Online(SP-O) through BCS

Implementation of WCF REST Web Service

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

I will not explain a WCF service implementation here, since there are lots of blogs out there on WCF REST services implementation. Create new WCF service project from Visual Studio and add below CRUD operations:
  • Create Item
  • Read Item
  • Read All Items
  • Update Item
  • Delete item
Let’s say CUSTOMER is a table in Database with below columns which are pretty much self-explanatory:
  • customerID
  • FirstName
  • LastName
Operations supported by WCF service would more likely be as below:

        public List<Customer> ReadList()
        {
//Read all items Code goes here         
        }

        public bool Update(int customerID, string FirstName,string LastName)
        {
// Update item Code goes here           
        }

        public bool Create(int customerID, string FirstName,string LastName)
        {
// New Item Code goes here       

        }

        public void Delete(int customerID)
        {
//Delete item Code goes here            

        }

        public Customer ReadItem(int customerID)
        {
//Get Item  by ID Code goes here        

        }
You can follow this blog for WCF REST service implementation. Post implementation of WCF serice publish it to IIS and make a DNS entry of it so that we can use it over internet and can access it from SharePoint online site.
So assuming that our web service is ready we will move forward to the next step.

WCF Service Integration with SP-O through BCS

The External Content Type (ECT) is a core concept of BCS through which we can integrate external data with SharePoint. Open your site in SharePoint designer and follow some easy steps to create ECT.

    1.Open SharePoint designer, select external content types and click Add connections. Select WCF service as a Data Source.



    2.Fill the details in WCF connection dialog box as follows:

2.1 For the Service Metadata URL setting, type the URL of the service endpoint created in STEP1, appending the ?wsdl string to the end of the URL. e.g.https://www.abcd.com:41003/WCFCustomer.svc?wsdl.
2.2 In the Metadata Connection Mode field, select WSDL.
2.3 In the Service Endpoint URL field, type the service endpoint URL. For example, type http://www.abcd.com:41003/WCFCustomer.svc
2.4 In the Name field, type WCFCustomer.

Note: Our web service does not have authentication, so we can connect with user’s identity. Otherwise we need to create a Secure Store Application ID entry from SharePoint Admin center. Secure Store Application ID entry will have credentials which can be used to authenticate user to access a web service.

    3.SharePoint designer will validate the connection and it will get displayed in Data Source Explorer. Expand the connection and we will be able to see all the methods that we have implemented in a web service.



Note: User must have Edit and Execute permissions in Metadata store, otherwise it will give an error saying Access denied by BDC. We assign metadata store permissions to user through SharePoint admin center in BCS by select ting “Manage BDC Models and External Content Types

    4. We need to define supported operations for the external content type.
    1. Right-click the ReadItem method in the Data Source Explorer, and then click New Read Item Operation on the context menu.
    2. In the Read Item wizard that opens, click Next on the Operation Properties page to keep the default Operation Name and Operation Display Name values for the operation.
    3. On the Input Parameters Configuration page, notice that there is an error in the Error Messages group box about an identifier field for this external content type that should be specified. To do this, select the CustomerId field in the Data Source Elements group box, and then select the Map to Identifier check box in the Properties group box. This sets the CustomerID field as an identifier for this external content type, not only for this parameter. The error message disappears. Following figure shows the Read Item operation input parameters.

  Figure: Read Item operation input parameters
    1. Click Next to continue to the Return Parameter Configuration page.
    2. On the Return Parameter Configuration page expand the ReadItem node in the Data Source Elements group box.
    3. Click the CustomerID parameter in the Data Source Elements group box.
    4. Select the Map to Identifier check box in the Properties group box. Notice that field is automatically marked Read-Only.
    5. Map the FirstName field and LastName field to Office properties. Select the FirstName field in the Data Source Elements group box, and then select the First Name (FirstName) property from the drop-down list for the Office Property setting in the Properties group box. Repeat this process for the LastName field, mapping it to the Last Name (LastName) Office property. Following figure shows the Read Item operation return parameter.
    6. Click Finish to complete the creation of the Read Item operation.

Figure: Read Item operation return parameter

Similarly create External Content Type Operations for ReadAll, Create, Update and Delete operations.

    5. ECT is ready for use post implementation of all ECT operations. Click on ‘Create List and Forms’ in SharePoint designer and fill the details to create specific list and forms. It will create a list as well as forms which will be an InfoPath form.



Create an external list from SharePoint site using this external content type and that’s it. 



Hope it helps somebody to quick start with BCS and SharePoint Online. Any comments, questions are welcome. :)

5 Steps to achieve Lazy Loading in SharePoint

Hello SharePointers!   Through this blog, I will walk you through a JS library implemented by me which helps us to load SharePoint list it...