当前位置: 首页>>代码示例>>C#>>正文


C# Web.GetPublishingPage方法代码示例

本文整理汇总了C#中Web.GetPublishingPage方法的典型用法代码示例。如果您正苦于以下问题:C# Web.GetPublishingPage方法的具体用法?C# Web.GetPublishingPage怎么用?C# Web.GetPublishingPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Web的用法示例。


在下文中一共展示了Web.GetPublishingPage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddPublishingPage

        public static void AddPublishingPage(PublishingPage page, ClientContext ctx, Web web)
        {
            SPPublishing.PublishingPage publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            RemovePublishingPage(publishingPage, page, ctx, web);

            web.AddPublishingPage(page.FileName, page.Layout, page.Title, false); //DO NOT Publish here or it will fail if library doesn't enable Minor versions (PnP bug)

            publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
            pageFile.CheckOut();

            if (page.Properties != null && page.Properties.Count > 0)
            {
                ctx.Load(pageFile, p => p.Name, p => p.CheckOutType); //need these values in SetFileProperties
                ctx.ExecuteQuery();
                pageFile.SetFileProperties(page.Properties, false);
            }

            if (page.WebParts != null && page.WebParts.Count > 0)
            {
                Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr = pageFile.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);

                ctx.Load(mgr);
                ctx.ExecuteQuery();

                AddWebpartsToPublishingPage(page, ctx, mgr);
            }

            List pagesLibrary = publishingPage.ListItem.ParentList;
            ctx.Load(pagesLibrary);
            ctx.ExecuteQueryRetry();

            ListItem pageItem = publishingPage.ListItem;
            web.Context.Load(pageItem, p => p.File.CheckOutType);
            web.Context.ExecuteQueryRetry();            

            if (pageItem.File.CheckOutType != CheckOutType.None)
            {
                pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
            }

            if (page.Publish && pagesLibrary.EnableMinorVersions)
            {
                pageItem.File.Publish(String.Empty);
                if (pagesLibrary.EnableModeration)
                {
                    pageItem.File.Approve(String.Empty);
                }
            }


            if (page.WelcomePage)
            {
                SetWelcomePage(web, pageFile);
            }

            ctx.ExecuteQuery();
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:60,代码来源:PageHelper.cs

示例2: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser,
            ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;

                web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url);

                foreach (PublishingPage page in template.Publishing.PublishingPages)
                {
                    string parsedFileName = parser.ParseString(page.FileName);
                    string parsedFullFileName = parser.ParseString(page.FullFileName);

                    Microsoft.SharePoint.Client.Publishing.PublishingPage existingPage =
                        web.GetPublishingPage(parsedFileName + ".aspx");

                    if (!web.IsPropertyAvailable("RootFolder"))
                    {
                        web.Context.Load(web.RootFolder);
                        web.Context.ExecuteQueryRetry();
                    }

                    if (existingPage != null && existingPage.ServerObjectIsNull.Value == false)
                    {
                        if (!page.Overwrite)
                        {
                            scope.LogDebug(
                                CoreResources.Provisioning_ObjectHandlers_PublishingPages_Skipping_As_Overwrite_false,
                                parsedFileName);
                            continue;
                        }

                        if (page.WelcomePage && web.RootFolder.WelcomePage.Contains(parsedFullFileName))
                        {
                            //set the welcome page to a Temp page to allow page deletion
                            web.RootFolder.WelcomePage = "home.aspx";
                            web.RootFolder.Update();
                            web.Update();
                            context.ExecuteQueryRetry();
                        }
                        existingPage.ListItem.DeleteObject();
                        context.ExecuteQuery();
                    }

                    web.AddPublishingPage(
                        parsedFileName,
                        page.Layout,
                        parser.ParseString(page.Title)
                        );
                    Microsoft.SharePoint.Client.Publishing.PublishingPage publishingPage =
                        web.GetPublishingPage(parsedFullFileName);
                    Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
                    pageFile.CheckOut();

                    if (page.Properties != null && page.Properties.Count > 0)
                    {
                        context.Load(pageFile, p => p.Name, p => p.CheckOutType);
                        context.ExecuteQueryRetry();
                        var parsedProperties = page.Properties.ToDictionary(p => p.Key, p => parser.ParseString(p.Value));
                        pageFile.SetFileProperties(parsedProperties, false);
                    }

                    if (page.WebParts != null && page.WebParts.Count > 0)
                    {
                        Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr =
                            pageFile.GetLimitedWebPartManager(
                                Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
                        context.Load(mgr);
                        context.ExecuteQueryRetry();

                        AddWebPartsToPublishingPage(page, context, mgr, parser);
                    }

                    List pagesLibrary = publishingPage.ListItem.ParentList;
                    context.Load(pagesLibrary);
                    context.ExecuteQueryRetry();

                    ListItem pageItem = publishingPage.ListItem;
                    web.Context.Load(pageItem, p => p.File.CheckOutType);
                    web.Context.ExecuteQueryRetry();

                    if (pageItem.File.CheckOutType != CheckOutType.None)
                    {
                        pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
                    }

                    if (page.Publish && pagesLibrary.EnableMinorVersions)
                    {
                        pageItem.File.Publish(String.Empty);
                        if (pagesLibrary.EnableModeration)
                        {
                            pageItem.File.Approve(String.Empty);
                        }
                    }

                    if (page.WelcomePage)
                    {
                        SetWelcomePage(web, pageFile);
                    }
//.........这里部分代码省略.........
开发者ID:SPParseError,项目名称:PnP-Sites-Core,代码行数:101,代码来源:ObjectPublishingPages.cs


注:本文中的Web.GetPublishingPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。