I'm trying to programatically(c#) add a user to a sharepoint People web part on a modern page but with no success.

I try to set the "persons"-property the same way it looks after adding a person manually.

    var peopleComp = page.InstantiateDefaultWebPart(DefaultClientSideWebParts.People);

    dynamic json = JObject.Parse(peopleComp.PropertiesJson.ToString());

    json["persons"] = "[{\"id\":\"i:0#.f|membership|user@mail.com\",\"upn\":\"user@mail.com\",\"role\":\"IT\",\"department\":\"IT\",\"phone\":\"\",\"sip\":\"\"}]";


I get no errors but the control is added with no user.

Anyone knows how to do this?

  • If I try to set peopleComp["persons"] instead of propertiesJson the site presents a "load people" symbol when opening but never gets finnished – Anders Nyström Dec 18 '18 at 11:47
var peopleComp = page.InstantiateDefaultWebPart(DefaultClientSideWebParts.People);

if (peopleComp != null)
      peopleComp.Title = "people";
      peopleComp.PropertiesJson = "{'layout':1, 'persons':[{'id':'i:0#.f|membership|USERMAIL'}],'title':''}";


page.Save(your site url)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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