Ejemplo n.º 1
0
        /// <summary>
        /// Gets the content and parts for wiki and publishing pages
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="web"></param>
        /// <param name="fileUrl"></param>
        /// <param name="file"></param>
        /// <param name="pageContentFieldName"></param>
        /// <param name="newFileCreator"></param>
        private void ProcessWikiOrPublishingPage(ClientContext ctx, Web web, string fileUrl, File file, string pageContentFieldName, FileCreator newFileCreator)
        {
            OnVerboseNotify("Processing Wiki or Publishing Page " + fileUrl);
            //Get the web part manager
            var webPartManager = TryToGetWebPartManager(ctx, file);

            if (webPartManager != null)
            {
                OnVerboseNotify("Processing web parts");
                var listIds = GetWebListIds(ctx, web);

                //Get each web part and do token replacements
                var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds);

                var pageContentListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml);

                //Get the field contents
                var pageContent = file.ListItemAllFields.FieldValuesForEdit[pageContentFieldName];

                newFileCreator.WebParts = webPartsXml;
                newFileCreator.WikiPageWebPartListViews = pageContentListViews;

                //Extract the storage keys
                var storageKeys = WikiPageUtility.GetStorageKeysFromWikiContent(pageContent);

                //Fetch the page
                var page = RequestContextCredentials == null
                    ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl)
                    : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl);

                //Search throught the page looking for the web part ID's that match the storage keys
                newFileCreator.WikiPageWebPartStorageKeyMappings = WikiPageUtility.GetStorageKeyMappings(page,
                                                                                                         storageKeys);
            }
        }
Ejemplo n.º 2
0
        private void UpdateWikiOrPublishingContentWithStorageKeys(Dictionary <string, string> newIdMappings, Web web, string contentFieldName)
        {
            var pageContent = ListItemFieldValues.Find(p => p.FieldName == contentFieldName)?.Value ?? String.Empty;

            File.ListItemAllFields[contentFieldName] =
                WikiPageUtility.GetUpdatedWikiContentText(pageContent, WikiPageWebPartStorageKeyMappings,
                                                          newIdMappings)
                .Replace("{@WebServerRelativeUrl}", web.ServerRelativeUrl != "/" ? web.ServerRelativeUrl : "");
            File.ListItemAllFields.Update();
            File.Context.ExecuteQuery();
        }