Esempio n. 1
0
        public void ShouldGetWebPart()
        {
            var svc = new WebPartPagesWebServiceSoapClient();

            svc.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(_appSettings.Username, _appSettings.Password, "SSW2000");

            var xx = svc.GetWebPart2("/Pages/Rules-to-Successful-Projects.aspx", new Guid("abedc3a2-8283-4264-87c4-31201fe8274b"), SpWebPartService.Storage.Shared, SPWebServiceBehavior.Version3);

            xx.Should().NotBeNull();
        }
        private void ExtractWebParts(Category cat, ListItem page, ClientContext ctx)
        {
            var file = ctx.Web.GetFileByServerRelativeUrl($"/Pages/{page["FileLeafRef"]}");

            ctx.Load(file);
            ctx.ExecuteQuery();
            // look for any web parts under this page.
            var wpManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
            var webParts  = wpManager.WebParts;

            ctx.Load(webParts);
            ctx.ExecuteQuery();

            if (webParts.Count > 0)
            {
                _log.LogInformation("Processing {Count} WebParts", webParts.Count);
                foreach (var webPart in webParts)
                {
                    _log.LogInformation("got web part id: {Id}", webPart.Id);
                    var svc = new WebPartPagesWebServiceSoapClient();
                    svc.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(_appSettings.Username, _appSettings.Password, "SSW2000");

                    var webPartXmlString = svc.GetWebPart2(file.ServerRelativeUrl, webPart.Id, SpWebPartService.Storage.Shared, SPWebServiceBehavior.Version3);
                    var xmlDoc           = XDocument.Parse(webPartXmlString);
                    var contentElement   = xmlDoc.Root.Elements().FirstOrDefault(e => e.Name.LocalName == "Content");
                    if (contentElement != null)
                    {
                        cat.Content = contentElement.Value;
                        if (cat.Content != null)
                        {
                            MatchEvaluator matchEval = new MatchEvaluator(ReplaceRelativeURl);
                            cat.Content = Regex.Replace(cat.Content, @"(""(\/_layouts\/15\/FIXUPREDIRECT.ASPX).*""\s)", matchEval);
                        }
                        _log.LogInformation($"got web part content {contentElement.Value}");
                    }
                }
            }
        }