How to Add Video Embed Webpart on SharePoint Office 365 Modern pages using C# CSOM Programmatically

Sathish Nadarajan
 
Solution Architect
January 8, 2019
 
Rate this article
 
Views
3542

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.

Category : Office 365

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment