예제 #1
0
        public static void AddWikiPageByUrl(this Web web, string serverRelativePageUrl, string html = null)
        {
            string folderName = serverRelativePageUrl.Substring(0, serverRelativePageUrl.LastIndexOf("/"));
            Folder folder     = web.GetFolderByServerRelativeUrl(folderName);
            File   file       = folder.Files.AddTemplateFile(serverRelativePageUrl, TemplateFileType.WikiPage);

            web.Context.ExecuteQuery();
            if (html != null)
            {
                web.AddHtmlToWikiPage(serverRelativePageUrl, html);
            }
        }
예제 #2
0
        public static void AddLayoutToWikiPage(this Web web, WikiPageLayout layout, string serverRelativePageUrl)
        {
            string html = "";

            switch (layout)
            {
            case WikiPageLayout.OneColumn:
                html = WikiPage_OneColumn;
                break;

            case WikiPageLayout.OneColumnSideBar:
                html = WikiPage_OneColumnSideBar;
                break;

            case WikiPageLayout.TwoColumns:
                html = WikiPage_TwoColumns;
                break;

            case WikiPageLayout.TwoColumnsHeader:
                html = WikiPage_TwoColumnsHeader;
                break;

            case WikiPageLayout.TwoColumnsHeaderFooter:
                html = WikiPage_TwoColumnsHeaderFooter;
                break;

            case WikiPageLayout.ThreeColumns:
                html = WikiPage_ThreeColumns;
                break;

            case WikiPageLayout.ThreeColumnsHeader:
                html = WikiPage_ThreeColumnsHeader;
                break;

            case WikiPageLayout.ThreeColumnsHeaderFooter:
                html = WikiPage_ThreeColumnsHeaderFooter;
                break;

            default:
                break;
            }

            web.AddHtmlToWikiPage(serverRelativePageUrl, html);
        }
예제 #3
0
        /// <summary>
        /// Applies a layout to a wiki page
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="folder">System name of the wiki page library - typically sitepages</param>
        /// <param name="layout">Wiki page layout to be applied</param>
        /// <param name="page">Name of the page that will get a new wiki page layout</param>
        public static void AddLayoutToWikiPage(this Web web, string folder, WikiPageLayout layout, string page)
        {
            string html = "";

            switch (layout)
            {
            case WikiPageLayout.OneColumn:
                html = WikiPage_OneColumn;
                break;

            case WikiPageLayout.OneColumnSideBar:
                html = WikiPage_OneColumnSideBar;
                break;

            case WikiPageLayout.TwoColumns:
                html = WikiPage_TwoColumns;
                break;

            case WikiPageLayout.TwoColumnsHeader:
                html = WikiPage_TwoColumnsHeader;
                break;

            case WikiPageLayout.TwoColumnsHeaderFooter:
                html = WikiPage_TwoColumnsHeaderFooter;
                break;

            case WikiPageLayout.ThreeColumns:
                html = WikiPage_ThreeColumns;
                break;

            case WikiPageLayout.ThreeColumnsHeader:
                html = WikiPage_ThreeColumnsHeader;
                break;

            case WikiPageLayout.ThreeColumnsHeaderFooter:
                html = WikiPage_ThreeColumnsHeaderFooter;
                break;

            default:
                break;
            }

            web.AddHtmlToWikiPage(folder, html, page);
        }
예제 #4
0
        //TODO: refactor this
        private void AddWebParts(Web web, Page page, TokenParser parser)
        {
            var url = parser.ParseString(page.Url);
            ContentPage contentPage = page as ContentPage;
            if (contentPage != null)
            {
                var file = web.GetFileByServerRelativeUrl(url);
                file.CheckOut();
                foreach (var model in contentPage.WebParts)
                {
                    try
                    {
                        model.Contents = parser.ParseString(model.Contents);

                        string oldId = null;
                        string newId = null;
                        if (!WebPartsModelProvider.IsV3FormatXml(model.Contents))
                    {
                            var id = WebPartsModelProvider.GetWebPartControlId(model.Contents);
                            var idToReplace = GetNewControlId();
                            model.Contents = model.Contents.Replace(id, idToReplace);
                            newId = this.GetIdFromControlId(idToReplace);
                            oldId = this.GetIdFromControlId(id);
                        }

                        var addedWebPart = this.AddWebPart(web, model, file);
                        newId = newId ?? addedWebPart.Id.ToString().ToLower();
                        oldId = oldId ?? GetWebPartIdFromSchema(model.Contents).ToLower();
                        parser.AddToken(new IdToken(web, newId, oldId));
                    }
                    catch (Exception ex)
                        {
                        Log.Error(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, "Could not add webpart: {0} - {1}", ex.Message, ex.StackTrace);
                        }
                    }

                var html = parser.ParseString(contentPage.Html);
                if (!string.IsNullOrEmpty(html))
                    {
                    web.AddHtmlToWikiPage(url, html);
                }
                file.CheckIn(String.Empty, CheckinType.MajorCheckIn);
                return;
            }
        }