I add my sharepoint framework webpart in AddForm.aspx page in my list. I want to get current list title. enter image description here How to do this?

When i use _spPageContextInfo i have following properties for list:

enter image description here

  • can you check with this.context.pageContext.legacyPageContext.listTitle ? Oct 24, 2017 at 11:31
  • not working :( Cannot find a property listTitle
    – Goshky
    Oct 24, 2017 at 11:36
  • 2
    hmm, can you try it as let listTitle: string = (<any>window)._spPageContextInfo.listTitle; first in your render method and then assign it your addform property ? Oct 24, 2017 at 11:45
  • i'll try with this...
    – Goshky
    Oct 24, 2017 at 12:39
  • 1
    Cool , have added it as an answer. Request you to please accept it. Thanks:) Nov 3, 2017 at 18:04

1 Answer 1


Looks like list title value is not present in the _spPageContextInfo object in SP 2016 OnPrem.

Also, looks like on the classic page AddForm.aspx, the this.context.pageContext is undefined.

So, as a workaround, you can make you of the classic _spPageContextInfo object's pageListId value. This will give you the list id using which you can make the REST API call

To use it in your webpart, you can use the below code:

 let listId: string = (<any>window)._spPageContextInfo.pageListId;

And use it somewhat as below;

var restUrl: string = this.context.pageContext.web.absoluteUrl + 
                      "/_api/Web/Lists(guid'" + listId + "')/items";

this.context.spHttpClient.get(restUrl, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => { 
...your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.