{"id":5364,"date":"2019-08-20T10:34:27","date_gmt":"2019-08-20T10:34:27","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=5364"},"modified":"2019-08-20T10:34:27","modified_gmt":"2019-08-20T10:34:27","slug":"how-to-extract-modern-page-webparts-using-pnp-core","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/","title":{"rendered":"How to extract modern page webparts using PnP Core"},"content":{"rendered":"\n<p><strong>Get all Client Side Webparts from a SharePoint Modern page using PNP Core \/ How to extract modern page webparts using PnP Core<\/strong><\/p>\n\n\n\n<p>In CMOS we can get the webparts from a page using &#8216;Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager&#8217; object. We can get all webparts information by using &#8216;LimitedWebPartManager&#8217; except for the modern\/client site pages.<\/p>\n\n\n\n<p>We can get modern page webparts by using OfficeDevPnP.Core. In this blog, I am going to share all codes on how we can get all webparts information by using OfficeDevPnP.Core.<\/p>\n\n\n\n<p>First of all, we have installed OfficeDevPnP.Core dlls by using Nuget package. Go to solution explorer and click on &#8216;Manage Nuget Package&#8217;. Then navigate to &#8216;Browse&#8217; panel and paste &#8216;SharePointPnPCoreOnline&#8217; in the search box.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/SharePointPnPCoreOnline.jpg\" alt=\"\" class=\"wp-image-5365\"\/><\/figure><\/div>\n\n\n\n<p>You can see &#8216;SharePointPnPCoreOnline&#8217;, please select that can click on Install button present on the right side of that page. I have added the necessary screen-shots for better understanding.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/Console-application--1024x338.jpg\" alt=\"\" class=\"wp-image-5366\"\/><\/figure><\/div>\n\n\n\n<p>I am using a simple Console application to iterate all client-side webparts information. <\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Please follow the below code\u2026<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing OfficeDevPnP.Core;\nusing OfficeDevPnP.Core.Pages;\nusing Microsoft.SharePoint.Client;\n\nnamespace ConsoleApp4\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Web web = null;\n            File file = null;\n            ListItem item = null;\n            List sitePagesList = null;\n            ClientContext ctx = null;\n            ClientSideWebPart clientSideWebPart = null;\n\n            string siteUrl = string.Empty;\n            string userName = string.Empty;\n            string password = string.Empty;\n\n            \/\/Initializing AuthenticationManager\n            AuthenticationManager authMgr = new AuthenticationManager();\n\n            \/\/Site Url to scan\n            siteUrl = \"SiteUrlToScan\";\n\n            \/\/Login User name\n            userName = \"UserName\";\n\n            \/\/Login password\n            password = \"Password\";\n\n            \/\/Getting SharePoint Client Context by using PNP Core\n            using (ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))\n            {\n                try\n                {\n                    web = ctx.Web;\n\n                    \/\/loading sharepoint web instance\n                    ctx.Load(web);\n                    ctx.ExecuteQueryRetry();\n\n                    \/\/get list by using list name\n                    sitePagesList = web.Lists.GetByTitle(\"Site Pages\");\n\n                    \/\/getting item by using item id\n                    item = sitePagesList.GetItemById(1);\n\n                    ctx.Load(item, I => I.File, I => I.DisplayName);\n                    ctx.ExecuteQueryRetry();\n\n                    file = item.File;\n                    var page = ClientSidePage.Load(ctx, file.Name);\n                    var webParts = page.Controls.FindAll(c => c.Type.Name == \"ClientSideWebPart\");\n\n                    if (webParts != null &amp;&amp; webParts.Count > 0)\n                    {\n                        foreach (var webpart in webParts)\n                        {\n                            try\n                            {\n                                clientSideWebPart = (ClientSideWebPart)webpart;\n                                Console.WriteLine(clientSideWebPart.Title);\n                            }\n                            catch (Exception ex) { }\n                        }\n                    }\n\n                    Console.ReadLine();\n                }\n                catch (Exception ex) { }\n            }\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>In my code example, I have three webparts in Home.aspx page as mention in below screen-shots and also after running the above code you can found all those three client-side webparts in my result screen-shot.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/client-side-webparts-1024x537.jpg\" alt=\"\" class=\"wp-image-5367\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2019\/08\/3-1.jpg\" alt=\"\" class=\"wp-image-5368\"\/><\/figure><\/div>\n\n\n\n<p><strong>This solution is brought to you by our SharePoint professionals.<\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.softreetechnology.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Softree Technology<\/a><\/strong>&nbsp;employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.<\/p>\n\n\n\n<p>Be it SPFx or SharePoint add-in developments, <strong><a href=\"https:\/\/www.softreetechnology.com\/sharepoint-2019-developments\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"SharePoint 2019 developments (opens in a new tab)\">SharePoint 2019 developments<\/a><\/strong>, web part developments, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016\/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get all Client Side Webparts from a SharePoint Modern page using PNP Core \/ How to extract modern page webparts using PnP Core In CMOS we can get the webparts from a page using &#8216;Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager&#8217; object. We can get all webparts information by using &#8216;LimitedWebPartManager&#8217; except for the modern\/client site pages. We can get modern page webparts by using OfficeDevPnP.Core. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5366,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[290,43],"tags":[292,293,294,295,168,159],"class_list":["post-5364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pnp","category-sharepoint","tag-get-modern-page-webparts-using-pnp","tag-how-to-extract-modern-webparts-programmatically-using-pnp","tag-modern-web-parts-officedevpnp-core","tag-modern-web-parts-pnp-library","tag-office-365","tag-sharepoint-online"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to extract modern page webparts using PnP Core - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to extract modern page webparts using PnP Core - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"Get all Client Side Webparts from a SharePoint Modern page using PNP Core \/ How to extract modern page webparts using PnP Core In CMOS we can get the webparts from a page using &#8216;Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager&#8217; object. We can get all webparts information by using &#8216;LimitedWebPartManager&#8217; except for the modern\/client site pages. We can get modern page webparts by using OfficeDevPnP.Core. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-20T10:34:27+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to extract modern page webparts using PnP Core - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/","og_locale":"en_US","og_type":"article","og_title":"How to extract modern page webparts using PnP Core - Softree Technology","og_description":"Get all Client Side Webparts from a SharePoint Modern page using PNP Core \/ How to extract modern page webparts using PnP Core In CMOS we can get the webparts from a page using &#8216;Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager&#8217; object. We can get all webparts information by using &#8216;LimitedWebPartManager&#8217; except for the modern\/client site pages. We can get modern page webparts by using OfficeDevPnP.Core. [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/","og_site_name":"Softree Technology","article_published_time":"2019-08-20T10:34:27+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"How to extract modern page webparts using PnP Core","datePublished":"2019-08-20T10:34:27+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/"},"wordCount":299,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#primaryimage"},"thumbnailUrl":"","keywords":["get modern page webparts using pnp","how to extract modern webparts programmatically using pnp","modern web parts officedevpnp.core","modern web parts pnp library","office 365","SharePoint Online"],"articleSection":["PnP","SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/","name":"How to extract modern page webparts using PnP Core - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#primaryimage"},"thumbnailUrl":"","datePublished":"2019-08-20T10:34:27+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/how-to-extract-modern-page-webparts-using-pnp-core\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to extract modern page webparts using PnP Core"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=5364"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5364\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=5364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=5364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=5364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}