public override void AddPage(ListItem item, ProvisioningTemplate template)
        {
            string url = GetUrl(item, true);
            if (null == template.Pages.Find((p) => string.Equals(p.Url, url, System.StringComparison.OrdinalIgnoreCase)))
            {
                var fieldValues = item.FieldValues;

                var pageLayoutUrl = string.Empty;
                if (fieldValues.ContainsKey("PublishingPageLayout"))
                {
                    pageLayoutUrl = fieldValues["PublishingPageLayout"] == null ? "" : (fieldValues["PublishingPageLayout"] as FieldUrlValue).Url;
                }
                pageLayoutUrl = this.TokenParser.TokenizeUrl(pageLayoutUrl);

                string html = "";
                if (fieldValues.ContainsKey("PublishingPageContent"))
                {
                    html = fieldValues["PublishingPageContent"] == null ? " " : fieldValues["PublishingPageContent"].ToString();
                }

                var title = fieldValues["Title"] == null ? "" : fieldValues["Title"].ToString();

                bool needToOverwrite = NeedOverride(item);
                var webParts = GetWebParts(item);
                bool isHomePage = IsWelcomePage(item);
                PublishingPage page = new PublishingPage(url, title, html, pageLayoutUrl, needToOverwrite, webParts, isHomePage);
                template.Pages.Add(page);
            }
        }
Пример #2
0
        public bool Equals(PublishingPage other)
        {
            if (other == null)
            {
                return (false);
            }

            return (FileName == other.FileName &&
                Title == other.Title &&
                Layout == other.Layout &&
                Overwrite == other.Overwrite &&
                Publish == other.Publish &&
                WelcomePage == other.WelcomePage &&
                PublishingPageContent == other.PublishingPageContent &&
                WebParts.DeepEquals(other.WebParts) &&
                Properties.DeepEquals(other.Properties));
        }
        private static void AddWebPartsToPublishingPage(PublishingPage page, ClientContext ctx, Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr, TokenParser parser)
        {
            foreach (var wp in page.WebParts)
            {
                string wpContentsTokenResolved = parser.ParseString(wp.Contents).Replace("<property name=\"JSLink\" type=\"string\">" + ctx.Site.ServerRelativeUrl,"<property name=\"JSLink\" type=\"string\">~sitecollection");
                Microsoft.SharePoint.Client.WebParts.WebPart webPart = mgr.ImportWebPart(wpContentsTokenResolved).WebPart;
                Microsoft.SharePoint.Client.WebParts.WebPartDefinition definition = mgr.AddWebPart(
                                                                                            webPart,
                                                                                            wp.Zone,
                                                                                            (int)wp.Order
                                                                                        );
                var webPartProperties = definition.WebPart.Properties;
                ctx.Load(definition.WebPart);
                ctx.Load(webPartProperties);
                ctx.ExecuteQuery();

                if (wp.IsListViewWebPart)
                {
                    AddListViewWebpart(ctx, wp, definition, webPartProperties, parser);
                }
            }
        }
        private static void AddPublishingPage(ClientContext context, PublishingWeb webPub, ListItemCollection allPageLayouts, OfficeDevPnP.Core.Framework.Provisioning.Model.PublishingPage page)
        {
            ListItem layout = null;

            //try to get layout by Title
            layout = allPageLayouts.Where(x => x["Title"] != null && x["Title"].ToString().Equals(page.Layout)).FirstOrDefault();

            //try to get layout by DisplayName
            if (layout == null)
            {
                layout = allPageLayouts.Where(x => x.DisplayName == page.Layout).FirstOrDefault();
            }

            //we need to have a layout for a publishing page
            if (layout == null)
            {
                throw new ArgumentNullException(string.Format("Layout '{0}' for page {1} can not be found.", page.Layout, page.Name));
            }

            context.Load(layout);

            // Create a publishing page
            PublishingPageInformation publishingPageInfo = new PublishingPageInformation();

            publishingPageInfo.Name = page.Name;
            publishingPageInfo.PageLayoutListItem = layout;

            Microsoft.SharePoint.Client.Publishing.PublishingPage publishingPage = webPub.AddPublishingPage(publishingPageInfo);

            //publishingPage.ListItem.File.Approve(string.Empty);

            context.Load(publishingPage);
            context.Load(publishingPage.ListItem.File, obj => obj.ServerRelativeUrl);
            context.ExecuteQuery();
        }