0

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|[email protected]\",\"upn\":\"[email protected]\",\"role\":\"IT\",\"department\":\"IT\",\"phone\":\"\",\"sip\":\"\"}]";

    page.AddControl(peopleComp);
    page.Save(model.Url);

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

Anyone knows how to do this?

1
  • If I try to set peopleComp["persons"] instead of propertiesJson the site presents a "load people" symbol when opening but never gets finnished Commented Dec 18, 2018 at 11:47

1 Answer 1

0
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.AddControl(peopleComp);
}

page.Save(your site url)

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.