Saturday, August 7, 2021

What is PowerShell and why we use it?

 Ans:-

PowerShell is an automation scripting language from Microsoft

PowerShell is an automation scripting language. Therefore, most of the tasks that require many 'clicks' or are repetitive should be automated. PowerShell is used primarily for bulk actions, or complex automation tasks mixed with other files format like .csv, .json, or .XML, and will reduce most time consuming efforts in the long run.

If you need to create only one site collection, using PowerShell wouldn't really be beneficial.

you can change/remove them all at once on multiple sites, extract information like Users/Groups/Permissions, and even integrate with other platforms like Azure to automate your most complex tasks!

More examples where PowerShell is used:

Difference between forEach() and map() methods?

 Ans:-

1. The returning value

The forEach() method returns undefined and map() returns a new array with the transformed elements. 

const myAwesomeArray = [1, 2, 3, 4, 5]

myAwesomeArray.forEach(x => x * x)

//>>>>>>>>>>>>>return value: undefined


myAwesomeArray.map(x => x * x)

//>>>>>>>>>>>>>return value: [1, 4, 9, 16, 25]


2. Ability to chain other methods

map() is chainable. This means that you can attach reduce(), sort(), filter() and so on after performing a map() method on an array.


That's something you can't do with forEach() because, as you might guess, it returns undefined.


const myAwesomeArray = [1, 2, 3, 4, 5]

myAwesomeArray.forEach(x => x * x).reduce((total, value) => total + value)

//>>>>>>>>>>>>> Uncaught TypeError: Cannot read property 'reduce' of undefined

myAwesomeArray.map(x => x * x).reduce((total, value) => total + value)

//>>>>>>>>>>>>>return value: 55

What is SharePoint webhooks?

 Ans:-

SharePoint webhooks enable developers to build applications that subscribe to receive notifications on specific events that occur in SharePoint. When an event is triggered, SharePoint sends an HTTP POST payload to the subscriber. Webhooks are easier to develop and consume than Windows Communication Foundation (WCF) services used by SharePoint Add-in remote event receivers because webhooks are regular HTTP services (web API).

Currently webhooks are only enabled for SharePoint list items. SharePoint list item webhooks cover the events corresponding to list item changes for a given SharePoint list or a document library. SharePoint webhooks provide a simple notification pipeline so that your application can be aware of changes to a SharePoint list without polling the service. 

The following information is required for creating a new subscription:

  • Resource. The resource endpoint URL you are creating the subscription for. For example, a SharePoint List API URL.
  • Server notification URL. Your service endpoint URL. SharePoint sends an HTTP POST to this endpoint when events occur in the specified resource.
  • Expiration date. The expiration date for your subscription. The expiration date should not be more than 180 days. By default, subscriptions are set to expire 180 days from when they are created.

You can also include the following information if needed:

  • Client State. An opaque string passed back to the client on all notifications. You can use this for validating notifications, tagging different subscriptions, or other reasons.

What should I do to prepare for SPFx web part development?

 Ans:-

Here are some of the things that you can start doing in anticipation of SPFx web parts:

-Move all code to client side JavaScript as much as possible and using JSOM for all SharePoint transactions

-Change all server side code to make CSOM calls instead of in-process SharePoint API

-Start using Typescript wherever possible

-Convert full trust solutions to provider hosted add-ins wherever possible especially as web services which can be called from client side code

How do I complete tasks that require elevated permissions using SPFx web parts?

 Ans:-

All code that requires elevated permissions should be developed in provider hosted add-ins exposed as REST services which can be called from SPFx web parts.

How do I handle long running operations in SPFx?

 Ans:-

One way long running operations could be handled is using SharePoint web hooks on a list which stored the requests. SPFx web parts can simply update this list to initiate a long running operation with the web hook endpoint updating the list once the operation is done.

Can I use Angular with SPFx?

 Ans:-

Angular can be utilized through SPFx web parts although angular templates are not yet available for SPFx and thus setting up angular for use using SPFx takes are little bit more effort.

What is the use of Office Fabric UI?

 Ans:-

The Office Fabrice UI library provides a rich set of components that can be used in SPFx web parts. A complete list can be found here. Some of the important ones are People Picker and Dialogs.

How do I communicate with the SharePoint in SPFx web parts?

 Ans:-

If you use the Yeoman templates, there is a context object already set up for you which allows you to start using it right away and make the REST calls to SharePoint to perform basic SharePoint operations. The limitations of these calls are the same as that provided by SharePoint hosted add-ins. Any operation that needs to be executed beyond these can be done using Provider Hosted Add-in based web services.

What are the recommended development languages for building SPFx web parts?

 Ans:-

Typescript should be used as the language of choice for building SPFx web parts. As far as development frameworks are concerned, React.js is best suited for the development of SPFx web parts as there are pre-build templates available as well as various controls like the Office Fabric UI React components for developers to start using.

Handle large list operations in SharePoint Framework to avoid Threshold?

 Ans:-

Custom Implementation

Here is approach to get read the large list with paging implementation.
 
Consider we have a SharePoint list named “LargeList” with below schema:

Field NameType
Title Single line of text
Description Multiple lines of text
Category Single line of text
Quantity  Number

 
The model to represent above list item will be as below:

export interface ILargeListItem { 
     Title: string
     Description: string
     Category: string
     Quantity: number; 
}


Let us define our approach to handle large list:

  • We will define the page size as 5000 for example (maximum threshold limit). Please note, SharePoint internally fetches the items in the batch of 100 items.
  • The number of requests we will have to read entire large list will be: Number of list items / page size.
  • We will make asynchronous requests to read the list items in batch.
  • Wait for all asynchronous requests to finish

Implement a genetic method getPageListItems which returns items with paging, starting with index passed as an argument.

$skiptoken=Paged=TRUE%26p_ID=` + (index * Constants.Page_Size + 1)


The getPageListItems method implementation will look as follows:

private getPageListItems(listTitle: string, index: number): Promise<ILargeListItem[]> { 
    return new Promise<ILargeListItem[]>((resolve, reject): void => { 
    let requestUrl = this.context.pageContext.web.absoluteUrl 
        + `/_api/web/Lists/GetByTitle('` + listTitle + `')/items` 
        + `?$skiptoken=Paged=TRUE%26p_ID=` + (index * Constants.Page_Size + 1) 
        + `&$top=` + Constants.Page_Size 
        + `&$select=ID,Title,Description,Category,Quantity`; 
   
    this.context.spHttpClient.get(requestUrl, SPHttpClient.configurations.v1) 
    .then((response: SPHttpClientResponse) => { 
        response.json().then((responseJSON: any) => {   
            resolve(responseJSON.value);   
          });   
        }); 
    });  
}


Implement a method to get the latest item id. This will be our maximum limit to read the items.

public getLatestItemId(listTitle: string): Promise<number> { 
    return new Promise<number>((resolve: (itemId: number) => void, reject: (error: any) => void): void => { 
        sp.web.lists.getByTitle(listTitle) 
            .items.orderBy('Id'false).top(1).select('Id').get() 
            .then((items: { Id: number }[]): void => { 
                if (items.length === 0) { 
                    resolve(-1); 
                
                else 
                    resolve(items[0].Id); 
                
            }, (error: any): void => { 
                reject(error); 
            }); 
    }); 
}


The next step is to implement method the main method to make asynchronous requests to read the list items in batch.

public async getLargeListItems(listTitle: string): Promise<ILargeListItem[]> { 
    var largeListItems: ILargeListItem[] = []; 
   
    return new Promise<ILargeListItem[]>(async (resolve, reject) => { 
        // Array to hold async calls 
        const asyncFunctions = []; 
   
        this.getLatestItemId(listTitle).then(async (itemCount: number) => { 
            for (let i = 0; i < Math.ceil(itemCount / Constants.Page_Size); i++) { 
                // Make multiple async calls 
                let resolvePagedListItems = () => { 
                    return new Promise(async (resolve) => { 
                        let pagedItems:ILargeListItem[] = await this.getPageListItems(listTitle, i); 
                        resolve(pagedItems); 
                    }) 
                }; 
                asyncFunctions.push(resolvePagedListItems()); 
            
   
                       // Wait for all async calls to finish 
            const results: any = await Promise.all(asyncFunctions); 
            for (let i = 0; i < results.length; i++) { 
                largeListItems = largeListItems.concat(results[i]); 
            
   
            resolve(largeListItems); 
        }); 
    }); 
}

How to make responsive ?

 Ans:-

Step1: 

Setting The Viewport

The viewport is the user's visible area of a web page.

The viewport varies with the device, and will be smaller on a mobile phone than on a computer screen.

HTML5 introduced a method to let web designers take control over the viewport, through the <meta> tag.

You should include the following <meta> viewport element in all your web pages:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

This gives the browser instructions on how to control the page's dimensions and scaling.

The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).

The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.

Step 2


Containers

Bootstrap requires a containing element to wrap site contents and house our grid system. You may choose one of two containers to use in your projects. Note that, due to padding and more, neither container is nestable.

Use .container for a responsive fixed width container.

<div class="container">
  ...
</div>

Use .container-fluid for a full width container, spanning the entire width of your viewport.

<div class="container-fluid">
  ...
</div>

Step 3

Bootstrap includes a responsive, mobile first fluid grid system that appropriately scales up to 12 columns as the device or viewport size increases

Step 4

Media queries

We use the following media queries in our Less files to create the key breakpoints in our grid system.

/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }

We occasionally expand on these media queries to include a max-width to limit CSS to a narrower set of devices.

@media (max-width: @screen-xs-max) { ... }
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
@media (min-width: @screen-lg-min) { ... }

Difference between HTML and HTML 5?

 Ans:

FeaturesHtmlHtml5
definitionA hypertext markup language (HTML) is the primary language for developing web pages.HTML5 is a new version of HTML with new functionalities with markup language with Internet technologies.
Multimedia supportLanguage in HTML does not have support for video and audio.HTML5 supports both video and audio.
StorageThe HTML browser uses cache memory as temporary storage.HTML5 has the storage options like:application cache, SQL database, and web storage.
Browser compatibilityHTML is compatible with almost all browsers because it has been present for a long time, and the browser made modifications to support all the features.In HTML5, we have many new tags, elements, and some tags that have been removed/modified, so only some browsers are fully compatible with HTML5.
Graphics supportIn HTML, vector graphics are possible with tools LikeSilver light, Adobe Flash, VML, etc.In HTML5, vector graphics are supported by default.
ThreadingIn HTML, the browser interface and JavaScript running in the same thread.The HTML5 has the JavaScript Web Worker API, which allows the browser interface to run in multiple threads.
StorageUses cookies to store data.Uses local storage instead of cookies
Vector and GraphicsVector graphics are possible with the help of technologies like VML, Silverlight, Flash,etc.Vector graphics is an integral part of HTML5, SVG and canvas.
ShapesIt is not possible to create shapes like circles, rectangles, triangles.We can draw shapes like circles, rectangles, triangles.
Doc typeDoctype declaration in html is too long
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
The DOCTYPE declaration in html5 is very simple "<! DOCTYPE html>
Character EncodingCharacter encoding in HTML is too long.
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.0 Transitional // EN">
Character encoding declaration is simple <meta charset = "UTF-8">
Multimedia supportAudio and video are not the part of HTML4.Audio and video are essential parts of HTML5,like: <Audio>, <Video>.
Vector GraphicsIn HTML4, vector graphics are possible with the help of techniques like VML, Silver light and Flash.Vector graphics are an integral part of HTML5, SVG, and canvas.
Html5 uses cookies.It supplies local storage in place of cookies.
ShapesIt is not possible to draw shapes like circles, rectangles, triangles.Using html5, you can draw shapes like circles, rectangles, triangles.
Browser SupportWorks with all older browsersA new browser supports this.

Wednesday, July 21, 2021

How do I complete tasks that require elevated permissions using SPFx web parts?

 Ans:

All code that requires elevated permissions should be developed in provider hosted add-ins exposed as REST services which can be called from SPFx web parts.

How to integrate SPFX webpart in teams?

 Ans:- 

Locate the ./src/webparts/**/manifest.json file for the web part you'll use as the tab for the meeting app solution. Locate the supportedHosts property to include "TeamsTab":

{ "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json", "id": "..", "alias": "MyFirstTeamsMeetingAppWebPart", "componentType": "WebPart", "version": "*", //... "supportedHosts": ["SharePointWebPart", "TeamsTab"], //... }

Select the package in the SharePoint tenant App Catalog and select the Sync to Teams button at in the ribbon in the Files tab.


The last step is to test the meeting app in Microsoft Teams. To do this, you'll create a meeting that isn't a channel meeting and has at least one person invited to it:

  1. Open the Microsoft Teams desktop client.

  2. Create a new meeting using the Calendar app in the left-hand app bar.

  3. Invite someone to the meeting.

  4. Save the meeting.

  5. From the Calendar app, open the test meeting you created.

  6. Select the + (plus) button to the right of the existing tabs.

  1. Select your custom meeting app


What are the differences between seattle and oslo master pages in SharePoint?

 Ans:- 

Seattle:

  1.  Seattle is designed for intranet team collaboration portal with more features such as  social, content\site navigation and management,etc.
  2. There is a Left navigation is exist and we can set Top navigation for top level sites and sub sites

Oslo:

  1.  Oslo master page is designed for publishing site which focus on page layout and content rendering.
  2. moving the left navigation to the top, and removing the top navigation all together. Oslo has a wider layout for your content.

What are the difference between componentDidMount() and componentDidUpdate()

 Ans:-

componentDidMount()

componentDidMount() will be rendered immediately after a component is mounted. This method will render only once and all the initialization that requires DOM nodes should go here. Setting state in this method will trigger a re-rendering.


componentDidUpdate()

componentDidUpdate() is invoked immediately every time the updating occurs. This method is not called for the initial render.


You can understand more from this below example

import React from 'react';

class Example extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }
  componentDidMount() {

    //This function will call on initial rendering.
    document.title = `You clicked ${this.state.count} times`;

  }
  componentDidUpdate() {
     document.title = `You clicked ${this.state.count} times`;
   }

  render(){
    return(
      <div>
      <p>You clicked {this.state.count} times</p>
      <button onClick={() => this.setState({ count: this.state.count + 1 })}>
        Click me
      </button>
    </div>
    )
  }
}
export default Example;