Thursday, 25 July 2019

SPFx (SharePoint Framework)

What is Gulp-serve-Dev-Cert ?

  • We need to run the “gulp trust-dev-cert” one time in your development machine to trust the certificate – if you have already executed this command during the prerequisites of the SharePoint Framework installation

  • gulp trust-dev-cert will invoke a command (on Windows and Mac) to add the certificate used by SPFx to the Trusted Root Certification Authorities store for the current user. 



Major topics of SPFx :

Scaffolding webparts and extensions.
Debugging with Chrome.
Creating and attaching the UI.
Reading and manipulating data.

Why SPFx is best ?
  1. SPFx is a straight javascript that runs in browser.
  2. Compile and runs in browser.
  3. you are able to use whatever framework and whatever library.
  4. User cannot edit the script.
  5. SPFx performance is very fast and very useful.

Package.Json : 

Package-Solution.Json:


Config.Json:

  1. We can the configuration files.
  2. You can configure all external java-script, jqurey you can specify.
  3. We can see entry point of webpart.
     Ex:- GetListItemWebpart.js


Serve.Json:



Package.Solution.json

TsConfig.Json

Settings.Json

Tslint.Json
Deploy.Azure.Storage.Json


We will have Node Modules like Pnp anf Json, React all.

Import:- 
Export:-  

Src: We will have Src Directory. there we have webpart names.

We can see GetListItemsWebpart.ts.
In this file should have --   import { Version } from '@microsoft/sp-core-library';
In this file We can add Interfaces.
Interface 1 for customers Interface 2 for customers items.
Now required for function fetch the Data from list.

Fetch data Function
Private _GetListCustomerData()
{
}

Private _RenderListCustomer(Items: ISPlistCustomerItem[]);void
{
  
}

We have mapped to the ISPListCustomerItem Interface in _Renderlistcustomer Function.

1. After that run Integrate Terminal go to view->find Integrate Terminal.
2. Here is Integrate Terminal for deploying and testing the suggestion in the workbench.
3. Workbench: means we can test your webpart without actually deploying into sharepoint. Only       available for the workbench.
4.  Just type gulp serve. 
5. once run the above command in Terminal
6. localhost workbench will be open in default browser(IE Edge)
7. Or you can open workbench.aspx 
8. We can able to add webpart and check it.


Link for Code



Angular Elements:
Self Bootstrapping
Hosts Angular component inside custom element
i.e <MyElement>
Allows Angular to play well with other components on page
Angular and Angular elements are you can have multiple SPFx webparts are running on same page at the same time all playing very good each other.

Preparing visual studio code for debugging

Prepare the initial setup

    Install Yeoman and gulp
    - npm install -g yo gulp
   Install SPFx Yeoman SharePoint generator
   - npm install -g @microsoft/generator - SharePoint
  Get the project ready with  Yeoman
       - Automates setup of projects using templates
  Finally
   - gulp trust-dev-cert

run the initial setup(Running Yeoman for scaffolding web site)

--Open  command prompt as a administrator

-- c:\yourProejctspath\Proejctitle>yo @microsoft/generator - SharePoint
    after enter button now we can do yeoman generator.
    generator window will open
    it will ask solution name

What is your solution name?
  Myproject

Which base line packages do you want to target for your component(s)?
  -SharePoint online only
  - SharePoint 2016 onwards, including 2019 and sharepoint online
 -  SharePoint 2019 onwards, including sharepoint online

Where do you want to place the files? 
use the current folder

Which type of client -side component to create?
 Webpart
 Extensions

What is your webpart name?
 mycustomwebpart

Which framework would you like to use?
  >No javascript framework
  >React
  >Knockout

Once you select the framework. it will install all the node dependencies required for the project

after you select framework it will take few mins and fire up
after that Solution will be created.

c:\yourProejctspath\Proejctitle>gulp trust-dev-cert

after that we will ready see visual studio code

c:\yourProejctspath\Proejctitle>code .

after that visual studio code window will be opened

see the below Window


in the project solution you will webparts in src directory with various files



Install and configure debugging components
 Configure debugging:-
                            - installing debugger for chrome ( or other browser)

  • Go to extension tab
  • find the Debugger for chrome 4.11.1
  • click install and click reload.
  • if others browser search in extension search tab.
Now if go the debug tab you will localworkbench debugg 
click settings configure or Fix "launch.Json"
url will be form in different workbenches.
  • Local Workbench
  • Hosted Workbench


Developing the User-interface(UI)

  • Prepare the angular libraries
  • Starting the data service
  • Writing the home controller
  • Writing the app module
  • Writing and attaching the HTML
Preparing libraries
Angular
PnPjs - Is much better and easy get SharePoint data
Open up Commad prompt
write command - npm install @pnp...............


installed the all dependencies of angular js PnPjs.

In the solution next steps will be as below for write the functionality to events, models, module,services,HTML
  • Prepared the libraries
  • Started the data service
  • Write the code for home controller
  • Write the cope for app module
  • Write and attached the HTML

As per the above we can develop the Methods.

Testing the Methods in Local and Online
Go to Terminal
We can see google chrome Pop up in Local Host

  1. Click an add button in center of the page.
  2. After that will see the our custom webpart in All A to Z  and select it.
We can see google chrome Pop up in Online
find below


Deploying the webpart

  1.  Address tslint issues
  2. Check solution manifest
  3. Enabling the Office365 CDN
  4. Packaging the solution
  5. Deploying the solution

The solution Manifest -
  Package-soluton.json is the manifest file
  Contains settings like
    - $schmea
    - Solution
    - Id

Config.Json:
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"hello-world-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/helloWorld/HelloWorldWebPart.js",
"manifest": "./src/webparts/helloWorld/HelloWorldWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"HelloWorldWebPartStrings": "lib/webparts/helloWorld/loc/{locale}.js"
}
}

TSLink issue - 
  Its avoid the duplicate switch cases, duplicate variables

 Prepare the Package - 
    We should required Online Management shell for Prepare the Package

Enable the O365 CDN -

Verify Solution settings -
Locate "IncludeClientSideAssets":true
.True:assets served from O365 CDN.
.False:assets served from app catalog

     Packaging the solution with Gulp

--> Go to Terminal

- gulp bundle --ship
- gulp package-solution--ship
   Creates a feature for your webpart
   Stored safely in a .sppkg file
      - i.e. MycustomWebpart.sppkg

Finally
We want to find package file.
Go to SharePoint Directory and then we can find mycustomPorject.sppkg


Deploying the Solution

  1. Copy the solution file to the app catalog in SharePoint
  2. Install it on your site
  3. Add the web part
  4. Publish it.
  5. And Preview the Web part in SharePoint


Node.js download and install for install yeoman and gulp.
because once Node.js installed, we can run commands in node.js

npm - dependency manager for node.js server, can resolve transitive dependencies/dependency trees
Yeoman -  provided scaffolding, i.e skeleton projects
gulp same as grunt, but written in js only


SPFx Debugg: --> We can debugg by Chrome control.

configure debugging components
                             - installing debugger for chrome ( or other browser)
  • Go to extension tab
  • find the Debugger for chrome 4.11.1
  • click install and click reload.
  • if others browser search in extension search tab.
You can then start your local server by running

gulp serve --nobrowser

SPFx Deploy:  --> Go to Terminal
  • yo @microsoft/sharepoint
  • gulp bundle –ship
  • gulp package-solution --ship
--> Upload your SPFx webpart package to the SharePoint App Catalog. 
--> The package “.sppkg” file is created when you run gulp package-solution and it is saved into the directory.


gulp bundle --ship - this command will help us to bundle all the typescript files and it’s dependencies from node_modules into a single JavaScript compiled file.

Initially, the compiled typescript files are converted into JavaScript files and saved in lib folder and then from there the final bundle file will be saved in a folder called temp/deploy.

gulp package-solution --ship - this command will help us build the installation file I mean. sppkg file.

Make sure to mark the includeClientSideAssets as true in package-solution.json, this will help us to use Office 365 CDN.

https://www.c-sharpcorner.com/article/sharepoint-framework-debugging-spfx-solutions/

How do you add .sppkg file in CDN in SharePoint online?

Step 1: Create webpart
Step 2: Create SharePoint Library

Create a SharePoint Library “Myspfxwebparts” and give read permission to all users.
Step 3: Open code Visual Studio Code

Open the code in Visual code tool. Type in cmd : code .
Step 4: Update the CDN Path

We need to configure the CDN path, i.e SharePoint Library what we created. https://vv.sharepoint.com/sites/dev/Myspfxwebparts we have to configure our CDN path in write-manifests.json file. This file can be found in the config folder. i.e
{
  “cdnBasePath”: “https://vv.sharepoint.com/sites/dev/Myspfxwebparts”
}

Save the file. Switch to cmd prompt
Step 5: Package and Deploy the webpart

Generate the files to deploy in the SharePoint Library
gulp bundle –ship Generated files can be found in spfx-firstwebpart\temp\deploy folder upload the files in the SharePoint Library
https://vv.sharepoint.com/sites/dev/Myspfxwebparts
Create a .spapp file for this webpart to upload in App Catalog
gulp package-solution –ship Generated spapp file can be found in spfx-firstwebpart\sharepoint folder upload the spapp file in App catalog SharePoint will show you a popup and ask you to trust the client-side solution to deploy. Click Deploy
Step 6: Install the App


Open your SharePoint Site Go to “Add an App” Click “From Your Organization” Select and Click you app to install it.  Click here 

How to SPFX webparts in Classic page?
We can used by PnP Powersehll script. Click here




SPFX components:



call npm uninstall -g chalk
call npm uninstall -g loadash
call npm uninstall -g tar-fs
call npm uninstall -g update-notifier
call npm uninstall -g yeoman-generator
call npm uninstall -g yosay
call npm uninstall -g yo
call npm uninstall -g gulp
call npm uninstall -g @microsoft/generator-sharepoint
call npm install -g chalk
call npm install -g loadash
call npm install -g tar-fs
call npm install -g update-notifier
call npm install -g yeoman-generator
call npm install -g yosay
call npm install -g yo
call npm install -g gulp
call npm install -g @microsoft/generator-sharepoint
c:/venu/Md spfx
c:/venu/cd spfx
c:/spfx


yo @microsoft/sharepoint

npm shrinkwrap 


Done..

Next

gulp trust-dev-cert

gulp serve

Code .



npm install jquery --save
npm install @types/jquery --save

How to add jqurey external on config.json?


  1.  



This creates files under temp/deploy which need to be copied to the Assets folder of your site

  1. gulp build  
  2. gulp -ship


Running the below commands creates sppkg in your target path.
  1. gulp bundle --ship  
  2. gulp package-solution --ship




  1. clean cache with
    npm cache clean --force
  2. install the latest version of npm globally as admin:
    npm install -g npm@latest --force
  3. clean cache with
    npm cache clean --force
  4. Try to install your component once again.>








Developer certificate has to be installed ONLY once in your development environment, so you can skip this step, if you have already executed that in your environment.

gulp trust-dev-cert
Now that we have installed the developer certificate, enter the following command in the console to build and preview your web part:

gulp serve



                                               First Should Know Concepts of SPFX



  1. How to Set up your SharePoint Framework development environment





We can use any code editor -- i.e Visual studio code
Yeoman helps you kick-start new projects'
Yeoman generator for creating new web parts
The generator provides 1. common build tools, 2. common boilerplate code.
Yeoman SharePoint web part generator helps you quickly create a SharePoint client-side solution project.
install the SharePoint Framework Yeoman generator globally
Client-side web parts are client-side components that run inside the context of a SharePoint page




  1. How to setup-node-behind-web-proxy

npm config set proxy http://proxy.company.com:8080
npm config
set https-proxy http://proxy.company.com:8080


  1. Create build your first SharePoint client-side web part.
Create new proejct directory
Md spfx
Cd spfx

. To preview your web part, build and run it on a local web server.
.The client-side toolchain uses HTTPS endpoint by default. This setting can be configured in the serve.json
Gulp Serve -
This command executes a series of gulp tasks to create a local, node-based HTTPS server on localhost:4321 and localhost:5432.

SharePoint Workbench is a developer design surface that enables you to quickly preview and test web parts without deploying them in SharePoint

 + add icon
To add the HelloWorld web part, select the add icon.
Select the add icon in the canvas to reveal the toolbox

This opens the toolbox where you can see a list of web parts
The list includes the spfx1 web part as well other web parts available locally in your development environment.
We can add client side webpart into a client side page.
Now you're running your web part in a page hosted in SharePoint
Select the pencil icon on the far left of the web part to reveal the web part property pane


More info find below link




Find outdated packages
To find the outdated packages in your client-side project, including SharePoint Framework and other packages your project depends on, run the following command in a console in the same directory as your project.
shCopy
npm outdated
To identify the SharePoint Framework packages, look for the package names that start with the following npm scope and prefix:
textCopy
@microsoft/sp-


Retrieve lists from SharePoint site

  1. https://yourtenantprefix.sharepoint.com/_api/web/lists

You will use SharePoint REST APIs to retrieve the lists from the site, which are located at https://yourtenantprefix.sharepoint.com/_api/web/lists.

  1. SharePoint Framework includes a helper class spHttpClient to execute REST API requests against SharePoint



                 CSS add
const styles2 = require('./customCSS.css');

<div className="error1">text testsss</div>



What is logging mechanisim in SPFx?

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/connect-to-api-secured-with-aad

How to handle exception and logs in SPFx?

SharePoint Framework (SPFx) also has no exception to it and supports logging APIs which can be used during the lifecycle of the web part.

Ex:-  console.log(error);

1st - reference the Log class.

import { Log } from '@microsoft/sp-core-library';

2nd - Log your message from your WebPart

Log.verbose("HelloWorld", "Here is a verbose log", this.context.serviceScope);

Log.info("HelloWorld", "Here is an informational message.", this.context.serviceScope);

Log.warn("HelloWorld", "Oh Oh, this might be bad", this.context.serviceScope);


Log.error("HelloWorld", new Error("Oh No!  Error!  Ahhhhhh!!!!"), this.context.serviceScope);



https://www.c-sharpcorner.com/article/sharepoint-framework-logging/

How to convert Classic Page into Modern page in SharePoint online?

Ans:- PnP has come with an approach to help migrate our classic SharePoint pages to new modern look and feel.


There are a few things to notice -
  • Web parts on the Classic page are replaced with modern 1st party web parts.
  • Web parts not supported in the Modern SharePoint are not migrated.
What is SharePoint Online Retention Policy?

Plan Your SharePoint Online Retention Policy

1.When creating a retention policy, it’s important to make sure you understand how it will affect existing documents.
2. A retention policy specifies that a document will be deleted a certain amount of time after it has been created or modified.
3. When you apply a retention policy to a SharePoint site, it will apply to all documents -- even those that were created before the policy was applied.
4. So if you set a retention policy of three years from the creation date, and apply it to a site that contains documents that are over three years old, these documents will be deleted.
5. You also have the option to choose whether to apply the retention policy based on the creation date or the last modified date.


CDN Path Best Example:-


https://www.c-sharpcorner.com/article/sharepoint-framework-deploy-spfx-webparts-to-sharepoint-library/


Create Site columns and Content types in SPFx?

https://www.spguides.com/sharepoint-framework-create-site-column-content-types-and-list/


Tuesday, 9 April 2019

SharePoint Interview Questions - 2

1. How to get two lists data whereas one column details same in another list by rest api?
list1, list2

Ans:    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items?$Select=Title,EmployeeName,Salary,Dept/Title,Dept/Code&$expand=Dept",
            type: "GET",

2. Managed metadata navigation in SharePoint online?

Ans: Managed navigation lets you define and maintain your site navigation by using term sets. With managed navigation, it's not the location of your content that defines where in the navigation your content will appear, but how you tag your content with terms from a term set.

3. How to get Tasks list data of all sub sites in site collection?

Ans:  We can fetch by Content query web part. or Content search webpart


4. Difference between Remote Event Receiver and Event Receiver?
Remote Event Receiver:
1.A provider hosted app is must, which means you need additional infra 
2.Works using web services, you expose web services on your provider hosted app, 
3.that are called when an event is fired.
Only Client Object Model is available inside the 4.event receiver code, so you'll be limited by CSOM's limitations. 
5.This is the only option to override events if you have O365/SharePoint online. 
6.Using this approach makes your code future safe, when SOM is killed finally. 
7.This is the list of events available to override.

Event Receivers
1.No additional infra required to host event receiver code.
2.Works using code running in context of W3WP.exe in case of farm solutions and spucworkerprocess.exe in case of SandBox solutions.
3.Full fledged SOM API is available in case of farm solutions, no limits.
4.This is only available in On-Premises environment.
5.This might be deprecated or unsupported in future releases.
6.This is the list of events available to override in SER


5. Difference between STSADM and Poweshell commands, SharePoint online management shell.
  • STSADM and Powershell can be used to administer the SharePoint environment
  • registry operations are not supported
Powershell:
  • easily play around with system registry
  • PowerShell is Microsoft’s next-generation scripting language offering direct access to .NET objects, complex flow and structure capabilities
  • We can maniplulate 500 out-of-the-box cmdlets or by creating custom cmdlets. Management Shell is just a PowerShell instance that loads the sharepoint.ps1 script file.
SharePoint online management shell:
you can display all available SharePoint Online cmdlets using the command
Command: Get-Command *-SPO*
6. Difference between Site definition and Site template

7. What is App?
  Easy-to-use, stand-alone applications that perform tasks or address specific business needs.
  You can add apps to your site to customize it with specific functionality or to display information

       1. We can add App from your organization’s App Catalog 
       2. You can also buy apps from third-party developers by browsing the SharePoint store

Please make sure do SSL Enabled = "False" before deploy in solution properties(VS)
8. Diff between SharePoint hosted app and provider hosted app
9. Difference between App web url and Host web URL?

App web url:
  • SharePoint site where our app will deploy.
  • App Web domain contains main domain as well as App Hash URL ( Random Unique ID ).
  • After Every deployment it will change.
Host web url:
  • SharePoint site where our app will install. It always be a specific domain name.
  • It is Main Site of subweb (App Web).
host web, is installed on a host website at the following URL: https://ourserver.sharepoint.com/sites/marketing The app for SharePoint will be deployed to app web with a URL like the following: https://ourserver-edff2019ea6dacb.sharepoint.com/sites/marketing Notice that the app web URL contains the App ID (edf2019ea6dacb), which is a hexadecimal number generated when the app is installed.
11. What is Client id, Client Secret, IssuerID?
Client ID/Client Secret: The client ID is the one which is unique for every Provider Hosted Applications.
And the PowerShell Script to register this ClientID
The same can be done by the Site as well. 1. Go to the http://sitecollection/_layouts/15/appregnew.aspx 2. Enter the Values and click on the Generate.
3. Client ID need to add in web.config and AppManifest.xml
Issuer ID: This ID is the one which should be included on our Web.Config only of the Provider Hosted Applications

11. What is Tenant?

Tenant is a web application.
Who is have admin rights on web application level,
He can manage site collections, Ownership.
He can manage external sharing.
He can manage storage allocation.
He can manage external Taxonomy metadata across site collection.
10. Cross Domain call in sharepoint apps?
  1.  Javascript library SP.RequestExecutor.js located in layouts directory
  2. that(SP.RequestExecutor.js) can be referenced in client-side code that runs in the app domain that allows
  3. the remote app to successfully access data on the host web
11. What is IFrame in sharepoint App?
 IFrame is client side library
We are sending request from IFrame through out AppwebProxy.aspx in the run server side code.
 --> go to developer toll (f12)
--> Find Iframe 
--> it is loading a page calling appwebproxy.aspx
--> request are running on the server
12. What is Chrome control?
13. What is Cross domain calls in sharepoint App?
14. What is SP.Requestexecutor,Js?
from hostapp url_layouts/15
Once sp.requestexecutor,js is loaded then we can start executing our code
15. How does SharePoint trust your server side code?
  1. S2S (Server to Server trust)
  2. OAuth
16. What is concept of IssueID and clientID?


117. If A person given the solution to B person Can he able develop that solution in his machine?
Ans: 
18. If b person change the appid client sectret what are he needs to change in bottom of appreg.aspx??
Ans:  We need to generate Client id, Client Secret and  fill in “App Domain” and “Redirect URL”. In fact, this is the website where the app is hosted.
How many list items we can fetch from list and show on grid?
We can fetch many but can view on 5000
If list items 20000 can we fetch those items by jsom??
Yes
How many items we can fetch by rest api?
100 items
How to disable all inputs by jqurey
Ex. $(input)
Loop it get the all id's and set up disable the control
How to ename column that sp lookup volume by caml qurey?
<Query> <Where> <Eq> <FieldRef Name='RefCountry' /> <Value Type='Lookup'>India</Value> </Eq> </Where> </Query> To query by ID you have o setup LookupId='TRUE' attribute of FieldRef element <FieldRef Name='RefCountry' LookupId='TRUE' />


Provider hosted app


Business object layer in c# programming in web application development 
Enabling or Disabling Claims Based Authentication
Logging using SharePoint server object model
Filter by start and end dates using 'today'
catch (Exception ex)
{
    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("My Category", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
}
How to Create Users and bulk users in Office 365?

1. Active users - normal we can add as add user with details firstname, lastname.
2. Bulk users we can add by download csv and put the names with mail id's and then upload it.

Who is External users in Office 365?

1. Authenticated External Users
There are two main groups:

A. Existing authenticated external users:
Users who are already in your Office 365 user directory. For example, users who have previously accepted a sharing invitation or users who you have imported from another Office 365 or Azure Active Directory tenant. 
They are required to log into your system before accessing shared content.
B. Ad-hoc external users:
They are asked to verify their identity with a one-time code sent to their email. Since they are not required to log in, they don’t need a Microsoft account.
2. Anonymous External Users
These are external users who access your content via a link, so they don’t need to log in. Anonymous sharing is rather tricky since you can’t identify the person who opens up the link.

How to add external users(external sharing) in SharePoint online?

4 ways to setup external users in SharePoint.



What are levels of Office 365 external sharing?

You can granularly control how to apply the settings above to different services inside your Office 365:

SharePoint Online
Tenant level – settings located in the SharePoint admin center under Sharing
Site collection level – settings located in the SharePoint admin center under Site collections
OneDrive – settings located in the OneDrive admin center under Sharing
Office 365 Groups – settings located in the Office 365 Admin center under Settings > Services & add-ins, where you will find the Office 365 Groups.

How to control external sharing in the Office 365 admin center?

Link

1. go to admin centre
2. go to sites
3. select site and double click site url settings popup will come.
4. you can see Sharing Status.
5. there we can allow the external sharing yes(Let people Outside of Organisation).
6. So that team site would be able to access external users.(Allow your users send link to outside of organisation users)