Functional component | Class Component |
1.A functional component is just a plain JavaScript function which accepts props as an argument and returns a React element. | 1.A class component requires you to extend from React.Component and create a render function which returns a React element. This requires more code |
2. you cannot use setState() in your component. | 2.you can use setState() in your component. |
3. It contains less lines of code | 3. It contains more lines of codes |
4. It accepts only props | 4. It accepts both props and state |
5. syntax import React from 'react'; import ReactDOM from 'react-dom'; function Welcome(props){ return <h1>Hello,{props.name}</h1> } ReactDOM.render(<Welcome />,document.getElementById('root')); | 5. syntax import React from 'react'; import ReactDOM from 'react-dom'; class Welcome extends React.Component{ render(){ return <h1>Hello,{this.props.name}</h1> } } ReactDOM.render(<Welcome />,document.getElementById('root')); |
Friday, May 29, 2020
Difference between Functional and Class Components in react.js ?
What is folder structure of SharePoint Framework (spfx) webpart and what are the main files used in it.
Folders in Solution
src
- The code files are stored inside this folder
- Includes web part code file (HelloWorldWebPart.ts),
configuration JSON file (HelloWorldWebPart.manifest.json)
lib
- It contains processed code which can be bundled and
distributed
- All TypeScript files compiled to JavaScript files are
stored in this folder
dist
- Contains final distributed files
- Includes JavaScript bundle file –
HelloWorldWebPart.bundle.js
config
- Contains a set of JSON files for configuration
- Configuration files vary from bundling to packaging
node_modules
- Contains JavaScript modules downloaded by Node.js
typings
- Contains TypeScript typings files for various libraries
- Typings supports IntelliSense for JavaScript libraries
SharePoint
- Contains the final .spapp file post execution of ‘gulp
package-solution’ command
Major
Files in Solution
Web Part Class
(HelloWorldWebPart.ts)
This defines the entry point of the
web part. In our solution, we have only one web part class -
HelloWorldWebPart.ts located at src\webparts\helloWorld folder. The web part
class extends BaseClientSideWebPart. Each client-side web part should extend
from BaseClientSideWebPart, which provides basic functioning for the web part.
Property Type Interface (IHelloWorldWebPartProps.ts)
The interface resides in the same web part file. The web part class accepts
the property type of interface. This interface is used to define our own custom
properties for the web part. We can add any of the below type of properties.
- Button
- Checkbox
- Choice group
- Dropdown
- Horizontal rule
- Label
- Link
- Slider
- Textbox
- Multi-line Textbox
- Toggle
- Custom
The properties can be used in web
part as below.
- <p class="${ styles.description }">${escape(this.properties.description)}</p>
WebPart Manifest
HelloWorldWebPart.manifest.json
holds the metadata of web part such as display name, description, icon,
version, id.
Config.json
The configuration file contains the bundling information, the
components used in the solution and entry point of the solution.
This file also records the external references (for e.g.
jQuery) and its dependencies. Also, references to localization resources are
stored in this file.
deploy-azure-storage.json
This file is used while deploying the client-side web part to
Azure CDN. This file contains Azure storage account details.

package-solution.json
This file contains solution path configurations.

gulpfile.js
Defines gulp tasks to run.
package.json
Defines JavaScript library dependencies.
tsconfig.json
Defines settings for TypeScript compilation
Summary
Yeoman generators help to generate SPFx client-side web part
solution. The solution has a predefined structure. Each folder and file has its
own significance. It is important to understand the role of each file for
better development.
Thursday, May 28, 2020
What are steps to configure SharePoint framework?
- These are Node JS based tools which help in creating, building, and debugging SPFx solutions.
- Go to Node JS command prompt
- Enter the below command
- It will download yeoman and gulp packages, we are using -g parameter so that it would be installed globally across your Node JS environment.
- Next, we will install the SharePoint Yoeman generator which will help in creating the SPFx solution project structure.
- Run the below command in Node JS command prompt.
- Run the below command in Node JS command prompt.
- Go to Node JS command prompt, go to the required path where you wanted to create the SPFx project.
- Use 'md helloworld-webpart' command to create a directory and go to that directory using 'cd helloworld-webpart'
- Once in your folder, use below command to create a new SPFx project
- yo @microsoft/sharepoint
- It will take you to some questions one by one to create a required project based on your requirements.
- Now let's run 'gulp trust-dev-cert', you will be asked to install a certificate. Click yes
- Run the below command.
- It should open local workbench like below, click on Add icon and add Hello world web part to the page.
What is the life cycle of SharePoint framework?
- OnInit()
- render()
What is SharePoint client side webpart?
Client-side web parts support:
- Building with HTML and JavaScript.
- Both SharePoint Online and on-premises environments
What is SharePoint Framework(spfx) and its key features?
- It runs in the context of the current user and connection in the browser. There are no iFrames for the customization (JavaScript is embedded directly to the page).
- The controls are rendered in the normal page DOM.
- The controls are responsive and accessible by nature.
- It enables the developer to access the lifecycle in addition to render, load, serialize and deserialize, configuration changes, and more.
- It is framework-agnostic. You can use any JavaScript framework that you like: React, Handlebars, Knockout, Angular, and more.
- The toolchain is based on common open source client development tools such as npm, TypeScript, Yeoman, webpack, and gulp.
- Performance is reliable.
- End users can use SPFx client-side solutions that are approved by the tenant administrators (or their delegates) on all sites, including self-service team, group, or personal sites.
- SPFx web parts can be added to both classic and modern pages.
Monday, May 18, 2020
What is Team and Communication site?
- Team Site
- Communication site.
- Topic,
- Showcase,
- Blank.
Classic SharePoint vs Modern SharePoint?
Key Feature |
Classic SharePoint |
Modern SharePoint |
Custom
master page and page layouts |
Classic
SharePoint we able to set custom master page and page layouts by Out of Box
SharePoint. |
Modern
SharePoint does not support any custom master page and page layouts. Modern
SharePoint as its own layouts that fully responsive including all modern web parts. |
Responsiveness |
Classic
SharePoint is partially responsive including all classic web part. Classic
SharePoint is not mobile friendly. |
Modern
SharePoint comes with full responsiveness even all modern web parts. Modern
SharePoint comes with Team sites, modern list and library structure and
site pages. Modern SharePoint support all modern devices including mobiles,
tablets and surface devices. |
Secure
and Faster |
In Classic SharePoint
user have permission to add custom code (javascript), also have script editor
and content editor web part that render on the server side that’s why it
takes time to load on the browser with additional security issues. The user can also edit
pages in SharePoint designer. |
Modern SharePoint doesn’t allow any custom code even it does
not provide any script editor web part for custom code that’s why is more
secure and loads faster. |
List and Library improvements |
Classic SharePoint list and library level configuration are
most complicated task there is no easy interaction with these controls.
Classic SharePoint has ribbon containing all list and library configuration. |
Modern SharePoint has
many lists and library level improvements including easier filtering,
conditional formatting, and attention views, which have easy interaction. The modern list also
addressed 5000 list items threshold issues problem by automatically indexing. Modern SharePoint does
not have SharePoint ribbon so we miss some cool features that present in
classic SharePoint including save as template, export to excel etc. |
New feature |
Classic SharePoint also supports these modern services but
there are some limitation and configuration issues which are not in Modern
SharePoint case. |
Modern SharePoint comes with very cool features that easy to
configure and share data between these services including Flow, Forms,
PowerApps, PowerBI etc. with responsiveness. |
AlternateCSSUrl web property |
Supported |
Not supported |
Minimal Download Strategy (MDS) |
Supported |
Not supported |
Web part supports |
All SPFx web part is supported in Classic pages. |
We can’t use already created “classic” web parts on “modern”
pages but vice-versa are worked. |
Development Strategy |
For classic SharePoint
Microsoft give feature called SharePoint Add-in in the year 2013 for web part
creation. SharePoint add-in
requires a lot of infrastructure and efforts to create add-in more it comes
in two flavors: SharePoint-hosted and provider-hosted. SharePoint add-in runs
in an iframe. |
For modern SharePoint
pages, Microsoft gives feature called SharePoint Framework (SPFx) in the year
2016 for web part creation. SharePoint framework
relly on open source tooling which required fewer efforts. SharePoint framework
does not run in an iframe that’s why it capable of running in classic
SharePoint site pages also. |
Development Customizations |
Classic web parts
support JSLink for list/form customizations. Supports display
templates, master pages offer search result rendering customizations |
Modern web parts not
supported JSlink in list/form customization. Modern SharePoint
development is client side using JavaScript frameworks like Angular JS, React
JS, Node etc. all these open sources. SharePoint framework (SPFx)
are used to create modern web parts and extensions SPFx extensions can
help for Application Customizers, Field Customizers, and Command Sets. |
Tools for Development Customizations |
SharePoint Designer Infopath SharePoint Workflows Sandbox Solution CustomActions |
SharePoint
Framework(SPFx)- Web part and Extention PowerApps Microsoft Flow |
SharePoint Search |
The ”classic” search
experience can be found in SharePoint on-prem as well as in Office 365.
”Search Center” provides results from the search index. Full control on the
searchable strategy, define what results to be displayed with complete search
customization |
”Modern” search
experiences have been popping up in Office 365 only. Displaying relevant
content, moreover, suggesting what is supposed to be useful to the current
user but the modern search experience UI is not customizable. |
SharePoint Ribbon |
Present |
Not present |
Limitation
of Modern SharePoint:
- 1. Modern SharePoint has come for Office 365 online only. not for
on premises.
- 2.
For SharePoint Framework (SPFx) to build and deploy client-side
web part so you need Office 365 tenant admin permission to create an
app catalog site.
- 3.
No support for master pages and page layouts.
- 4.
No active SharePoint ribbon in modern SharePoint.
- 5.
Custom CSS via AlternateCSSUrl web property not supported
- 6.
Minimal Download Strategy (MDS) not supported
- 7.
Missing script editor and content editor web part.
What are zones in SharePoint Web Application?
- Default
- Intranet
- Internet
- Custom
- Extranet
- Authentication type (Windows Authentication/Kerberos)
- Network zone (Intranet/Internet/Extranet)
- Policy permissions (Allow or Deny Read-Write access)
How to resolve SharePoint list view threshold error: “The view cannot be displayed because it exceeds the list view threshold…”
The view cannot be displayed because it exceeds the list view threshold (5000 items) enforced by the administrator.
To view items, try selecting another view or creating a new view. If you do not have sufficient permissions to create views for this list, ask your administrator to modify the view so that it conforms to the list view threshold.
Supported and unsupported columns for indexing
Supported Column Types
|
Unsupported Column Types
|
Solution #1: Index Columns Used as View Filters
(works for both On-Prem/SharePoint Server AND O365/SharePoint Online)
1) Filter all views so that they cannot return more than the threshold limit (such as [Created] is greater than or equal to [Today]-120 to only return the last four months of data)
2) Index all columns used in list view filters ([Created], [Department], [Location], [Agent], etc.) You can index up to 20 columns. ShareGate also recommends indexing the first column in each list view.
- Go to List Settings
- Under “Columns” select “Indexed Columns”
- Click “Create a new index”
- Change primary column to the column on which you’re filtering and click Create
- Go to Central Admin
- Under “Application Management” click “Manage Web Applications”
- Select the web application for which you’re adjusting the list view threshold
- Select “General Settings” then “Resource Throttling”
- Change the limit and click OK.
- Check the result by going to “List Settings” for any list on that web application
- Cannot modify list view thresholds
- Cannot create a Daily Time Window
- You can only have 20 indexed columns per list. Plan thoughtfully!
- You can't create an indexed column if the list is already hitting the list view threshold.
- If you use additional sorting in a view, the sort column also needs to be an indexed column.
- Review the list items and check if some can be deleted or archived to another list.
Friday, May 15, 2020
Break Inheritance And Add Role Permissions Using REST API In SharePoint
We can implement this from UI directly. In order to do that we can navigate to the permissions management section of the Library/List Library. Settings -> Permissions for this Document Library.
Clicking on Stop Inheriting Permissions will grant unique permissions to the document library.
let’s break the inheritance using the BreakRoleInheritance method of REST API.
Say if my site had the URL: http://c293106922:1500, then the breakroleinheritance rest URL will look like:
“http://c293106922:1500/_api/web/lists/getByTitle('Documents')/breakroleinheritance(copyRoleAssignments=true, clearSubscopes=true)”
If I try to access the above Rest API from the browser it will give me the following error:
It states clearly that we cannot use GET to issue the rest call. Let’s create the REST header, REST end point and issue a POST request.
The entire rest call to break inheritance will look like the following code snippet:
//Create the REST header
var headers = {
"Accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
}
//Create the REST end point URL
var endPointUrl = "http://c293106922:1500/" + "_api/web/lists/getByTitle('Documents')/breakroleinheritance(copyRoleAssignments=true, clearSubscopes=true)";
//Issue the REST Call
var call = jQuery.ajax({
url: endPointUrl,
type: "POST",
headers: headers,
dataType: 'json',
success: function (data) {
alert(‘Inheritance Broken Successfully !');
},
error: function (error) {
alert(JSON.stringify(error));
}
});
Once the breakroleinheritance call is issued the child’s inheritance will lost and it will not have unique permissions.
Now let’s see how to assign Full Control permissions to the existing group SP2016 Test Members in the List using the method addroleassignment of REST API.
The rest API for this will look like: “http://c293106922:1500/_api/web/lists/getByTitle('Document')/roleassignments/addroleassignment(principalid=20,roleDefId=1073741828)“
There are two parameters whose values we need to know to issue the REST call.
Principalid
RoleDefid
Here Pricipalid is the id of the user/group to which we are going to assign Role Permissions.
This id can be obtained from browser by issuing a GET request as below:
http://c293106922:1500/_api/web /siteusers - to get the id of a user
http://c293106922:1500/_api/web /sitegroups - to get the id of a group
o our group SP2016 has an id of 8.
The second parameter is the RoleDefid which is the id of the Role Permission (Full Control, Edit, etc.)
We can get the id of the Role permission using the following GET request in the browser.
http://c293106922:1500/_api/web/roledefinitions
Thus full control has the id of : 1073741829.
Now we are all set to issue a POST REST call to add the Full Control Role Permission to SP2016 Test Members group.
var headers = {
"Accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
}
var endPointUrlRoleAssignment = "http://c293106922:1500/" + "_api/web/lists/getByTitle('Documents')/roleassignments/addroleassignment(principalid=8,roleDefId=1073741829)";
var call = jQuery.ajax(
{
url: endPointUrlRoleAssignment,
type: "POST",
headers: headers,
dataType: 'json',
success: function (data)
{
alert(Role Permission Added successfully!');
},
error: function (error)
{
alert(JSON.stringify(error));
}
});