In this article, let us see how to add a Video Embed Webpart Programmatically using C# in Office 365 Modern Pages.
1. Add the Video to the Video APP.
2. Upload the Videos.
3. Get the URL of the Videos
4. Execute the below Piece of code.
public static void AddVideoEmbedWebPartToModernPage()
{
try
{
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
{
var page2 = ctx.Web.AddClientSidePage("PageWithSections.aspx", true);
page2.AddSection(CanvasSectionTemplate.ThreeColumn, 5);
page2.Save();
ClientSideWebPart videoEmbedWp = page2.InstantiateDefaultWebPart(DefaultClientSideWebParts.VideoEmbed);
videoEmbedWp.Properties["videoSource"] = "https://sppalsmvp.sharepoint.com/portals/hub/_layouts/15/PointPublishing.aspx?app=video&p=p&chid=****&vid=*******";
videoEmbedWp.Properties["captionText"] = "video";
videoEmbedWp.Properties["showInfo"] = false;
//videoEmbedWp.Properties["embedCode"] = "<iframe width=853 height=480 src='https://sppalsmvp.sharepoint.com/portals/hub/_layouts/15/PointPublishing.aspx?app=video&p=p&chid=******&vid=*********&width=853&height=480&autoPlay=false&showInfo=true' allowfullscreen></iframe>";
videoEmbedWp.Title = "Associated video";
CanvasSection section = page2.Sections[0];
page2.AddControl(videoEmbedWp, section.Columns[1], 0);
page2.Save();
}
}
catch (Exception ex)
{
System.Console.WriteLine("Exception occurred : " + ex.Message);
System.Console.ReadLine();
}
}
Happy Coding,
Sathish Nadarajan.
Leave a comment