How to add a web part to a modern page programmatically in SharePoint 2019?

%3CLINGO-SUB%20id%3D%22lingo-sub-1322251%22%20slang%3D%22en-US%22%3EHow%20to%20add%20a%20web%20part%20to%20a%20modern%20page%20programmatically%20in%20SharePoint%202019%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1322251%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHello%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20am%20looking%20for%20a%20way%20to%20add%20a%20web%20part%20to%20a%20modern%20page%20programmatically%20in%20SharePoint%202019%20on%20premises.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWhat%20I%20want%20to%20accomplish%20is%20a%20custom%20news%20page%2C%20which%20has%20an%20additional%20site%20property%20%22Category%22%2C%20which%20can%20be%20displayed%20and%20edited%20through%20a%20web%20part.%20Is%20seems%20to%20be%20possible%20with%20Pnp%20in%20SharePoint%20Online%20as%20described%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Foffice%2Fblogs%2Fprogramming-modern-pages-with-zones-sections-news-and-home-pages%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bbut%20I%20can't%20find%20anything%20for%202019.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1322302%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20a%20web%20part%20to%20a%20modern%20page%20programmatically%20in%20SharePoint%202019%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1322302%22%20slang%3D%22en-US%22%3EAnother%20approach%20here%20could%20be%20to%20use%20PnP%20templates%20to%20get%20a%20template%20where%20you%20simply%20customize%20an%20existing%20page%20with%20the%20WebParts%20you%20want%20to%20add%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hello,

 

I am looking for a way to add a web part to a modern page programmatically in SharePoint 2019 on premises.

What I want to accomplish is a custom news page, which has an additional site property "Category", which can be displayed and edited through a web part. Is seems to be possible with Pnp in SharePoint Online as described here but I can't find anything for 2019.

 

Thanks!

1 Reply
Highlighted
Another approach here could be to use PnP templates to get a template where you simply customize an existing page with the WebParts you want to add