Sivarajan's Blog

SharePoint | Office 365 | Azure | JavaScript

SharePoint Framework Client WebPart–Playing with context, pageContext, Web, User and CultureInfo

Overview

As a SharePoint developer, we are familiar with SPContext. We can easily access the current Site, Web and User related information from SPContext.Current. In this post, we will see that how to get the similar details from SharePoint Framework Client WebPart.

Create a new WebPart

The prerequisites of SharePoint Framework Client Side development is that,

  • NodeJs
  • Visual Studio Code

I have explained in my previous posts on how to install and configure NodeJs and VS Code. In addition to that, here you find more details about creating a Hello World WebPart.

https://github.com/SharePoint/sp-dev-docs

this.Context (IWebPartContext)

This is a similar to SPContext. One of the important properties is pageContext and we can access the following properties from that,

  • Site
  • Web
  • User
  • CultureInfo

this.Context.pageContext.web

This will return the Absolute URL, Relative URL, Web site title and Web site unique ID. Here is the syntax for that.

09012016-1 

The output of the above code is,

09012016-2

this.Context.pageContext.user

This will return the logged in user’ loginName and displayName.

09012016-3

The output of the above code is,

09012016-4

this.Context.pageContext.cultureInfo

This will return the site culture information. Based on that, we can localize the webpart easily.

09012016-5

The output of the above code is,

09012016-6

Summary

In the post, we will see that few important SharePoint Framework properties. In the next post, we will see that, how to use httpClient object.

Add comment

Loading