Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public static void CreatePublishingPage(ClientContext clientContext, string pageName, string pagelayoutname, string url, string queryurl)
        {
            var publishingPageName = pageName + ".aspx";

            Web web = clientContext.Web;

            clientContext.Load(web);

            List pages = web.Lists.GetByTitle("Pages");

            clientContext.Load(pages.RootFolder, f => f.ServerRelativeUrl);
            clientContext.ExecuteQuery();

            Microsoft.SharePoint.Client.File file =
                web.GetFileByServerRelativeUrl(pages.RootFolder.ServerRelativeUrl + "/" + pageName + ".aspx");
            clientContext.Load(file, f => f.Exists);
            clientContext.ExecuteQuery();
            if (file.Exists)
            {
                file.DeleteObject();
                clientContext.ExecuteQuery();
            }
            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(clientContext, web);

            clientContext.Load(publishingWeb);

            if (publishingWeb != null)
            {
                List publishingLayouts = clientContext.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");

                ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                clientContext.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pagelayoutname));
                clientContext.ExecuteQuery();

                ListItem layout = allItems.Where(x => x.DisplayName == pagelayoutname).FirstOrDefault();
                clientContext.Load(layout);

                PublishingPageInformation publishingpageInfo = new PublishingPageInformation()
                {
                    Name = publishingPageName,
                    PageLayoutListItem = layout,
                };

                PublishingPage publishingPage = publishingWeb.AddPublishingPage(publishingpageInfo);
                publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                publishingPage.ListItem.File.Publish(string.Empty);
                clientContext.ExecuteQuery();
            }
            SetSupportCaseContent(clientContext, "SupportCasesPage", url, queryurl);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a publishing page under the specified site with the content type ID and specified title.
        /// Filename of the created page is automatically chosen to avoid collision to existing pages.
        /// </summary>
        /// <param name="currentWeb">Publishing web.</param>
        /// <param name="contentTypeId">Content type ID of the new page.</param>
        /// <param name="title">Title of the new page.</param>
        /// <exception cref="InvalidOperationException">Throws if there is no page layouts associated with the specified content type ID.</exception>
        /// <returns>A publishing page object.</returns>
        public static PublishingPage CreatePublishingPage(this PublishingWeb currentWeb, SPContentTypeId contentTypeId, string title)
        {
            CommonHelper.ConfirmNotNull(currentWeb, "currentWeb");
            CommonHelper.ConfirmNotNull(title, "title");

            PageLayout pageLayout = null;

            currentWeb.Web.Site.WithElevatedPrivileges(elevatedSite => {
                PublishingSite publishingSite = new PublishingSite(elevatedSite);

                IEnumerable <PageLayout> pageLayouts = publishingSite.GetPageLayouts(true).Where(p => p.AssociatedContentType != null);
                pageLayout = pageLayouts.FirstOrDefault(p => p.AssociatedContentType.Id == contentTypeId);
                if (pageLayout == null)
                {
                    pageLayout = pageLayouts.FirstOrDefault(p => p.AssociatedContentType.Id.IsChildOf(contentTypeId));
                }
                //pageLayout = publishingWeb.GetAvailablePageLayouts().FirstOrDefault(p => p.AssociatedContentType.Id == contentTypeId);
                //pageLayout = publishingWeb.GetAvailablePageLayouts(contentTypeId).FirstOrDefault();
            });
            if (pageLayout == null)
            {
                throw new InvalidOperationException(String.Format("Could not find available page layout for content type {0} at {1}", contentTypeId, currentWeb.Url));
            }

            MethodInfo getUniquePageName =
                typeof(PublishingPage).GetMethod("GetUniquePageName", true, typeof(string), typeof(bool), typeof(PublishingWeb), typeof(bool)) ??
                typeof(PublishingPage).GetMethod("GetUniquePageName", true, typeof(string), typeof(bool), typeof(PublishingWeb));

            if (getUniquePageName == null)
            {
                throw new MissingMethodException("PublishingPage", "GetUniquePageName");
            }
            object[] param = getUniquePageName.GetParameters().Length == 4 ?
                             new object[] { title, true, currentWeb, true } :
            new object[] { title, true, currentWeb };
            string         uniquePageName = getUniquePageName.Invoke <string>(null, param);
            PublishingPage publishingPage = currentWeb.AddPublishingPage(uniquePageName, pageLayout);

            publishingPage.Title = title;
            publishingPage.Update();
            return(publishingPage);
        }
Ejemplo n.º 4
0
        public void AddPublishingPage()
        {
            string pageName = "CustomPage3.aspx";
            Web    webSite  = context.Web;

            context.Load(webSite);
            PublishingWeb web = PublishingWeb.GetPublishingWeb(context, webSite);

            context.Load(web);

            if (web != null)
            {
                List pages = context.Site.RootWeb.Lists.GetByTitle("Pages");
                ListItemCollection defaultPages = pages.GetItems(CamlQuery.CreateAllItemsQuery());
                context.Load(defaultPages, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pageName));
                context.ExecuteQuery();
                if (defaultPages != null && defaultPages.Count > 0)
                {
                }
                else
                {
                    List publishingLayouts      = context.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");
                    ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                    context.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == "PageLayoutTemplate"));
                    context.ExecuteQuery();
                    ListItem layout = allItems.Where(x => x.DisplayName == "PageLayoutTemplate").FirstOrDefault();
                    context.Load(layout);
                    PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
                    publishingPageInfo.Name = pageName;
                    publishingPageInfo.PageLayoutListItem = layout;
                    PublishingPage publishingPage = web.AddPublishingPage(publishingPageInfo);
                    publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                    publishingPage.ListItem.File.Publish(string.Empty);
                    publishingPage.ListItem.File.Approve(string.Empty);
                    context.Load(publishingPage);
                    context.Load(publishingPage.ListItem.File, obj => obj.ServerRelativeUrl);
                    context.ExecuteQuery();
                }
            }
        }
Ejemplo n.º 5
0
        public static PublishingPage CreatePage(this SPWeb web, string pageName, string pageLayoutName)
        {
            if (!PublishingWeb.IsPublishingWeb(web))
            {
                return(null);
            }

            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

            PageLayout pageLayout =
                publishingWeb.GetAvailablePageLayouts().FirstOrDefault(
                    page => page.Name.Equals(pageLayoutName, StringComparison.InvariantCultureIgnoreCase));

            if (pageLayout == null)
            {
                return(null);
                //throw new SPException(string.Format("Page layout with name {0} is not found.", pageLayoutName));
            }

            PublishingPage newPage = publishingWeb.AddPublishingPage(pageName, pageLayout);

            return(newPage);
        }
Ejemplo n.º 6
0
        public static PublishingPage CreatePublishingPage(PublishingWeb CurrentPublishingWeb, string newPageName, PageLayout pageLayout, SPFolder folder, bool doCreateFriendlyUrl)
        {
            PublishingPage publishingPage = null;
            bool           tryNakedToken  = true;

            do
            {
                try
                {
                    if (doCreateFriendlyUrl)
                    {
                        newPageName = GetUniquePageName(newPageName, tryNakedToken, CurrentPublishingWeb, true, folder);
                    }
                    if (!newPageName.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        newPageName += ".aspx";
                    }
                    publishingPage = ((folder != null) ? CurrentPublishingWeb.AddPublishingPage(newPageName, pageLayout, folder) : CurrentPublishingWeb.AddPublishingPage(newPageName, pageLayout));
                    if (publishingPage != null && doCreateFriendlyUrl && publishingPage.ListItem.ParentList.ForceCheckout)
                    {
                        publishingPage.CheckIn(string.Empty);
                        publishingPage.CheckOut();
                    }
                }
                catch (SPException ex)
                {
                    if (doCreateFriendlyUrl && (ex.ErrorCode == -2130575306 || ex.ErrorCode == -2130575257))
                    {
                        tryNakedToken = false;
                        goto end_IL_0082;
                    }
                    throw;
                    end_IL_0082 :;
                }
            }while (doCreateFriendlyUrl && publishingPage == null);
            return(publishingPage);
        }
Ejemplo n.º 7
0
        protected void btnScenario1_Click(object sender, EventArgs e)
        {
            var    spContext          = SharePointContextProvider.Current.GetSharePointContext(Context);
            string ContosoWebPageCTId = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4002CA362904d604607B0F1E39BE59D76E0";

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                // Create content type for the page layouts
                if (!clientContext.Web.ContentTypeExistsByName("ContosoWebPage"))
                {
                    // Let's create a content type which is inherited from oob welcome page
                    clientContext.Web.CreateContentType("ContosoWebPage",
                                                        ContosoWebPageCTId,
                                                        "Contoso Web Content Types");
                }

                // Upload page layouts to the master page gallery
                clientContext.Web.DeployPageLayout(HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/ContosoLinksBelow.aspx")),
                                                   "Contoso Links Below", "Contoso Links Below", ContosoWebPageCTId);

                clientContext.Web.DeployPageLayout(HostingEnvironment.MapPath(string.Format("~/{0}", "Resources/ContosoLinksRight.aspx")),
                                                   "Contoso Links Right", "Contoso Links Right", ContosoWebPageCTId);

                // Add content type to Pages library
                clientContext.Web.AddContentTypeToListById("Pages", ContosoWebPageCTId);

                // Deploy addditional JS to site
                DeployJStoContosoFoldersInStyleLibrary(clientContext);

                // Create a new page based on the page layout
                List pages = clientContext.Web.Lists.GetByTitle("Pages");
                Microsoft.SharePoint.Client.ListItemCollection existingPages = pages.GetItems(CamlQuery.CreateAllItemsQuery());
                clientContext.Load(pages);
                clientContext.Load(existingPages, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == "demo"));
                clientContext.ExecuteQuery();

                // Check if page already exists and delete old version if existed
                if (existingPages != null && existingPages.Count > 0)
                {
                    existingPages[0].DeleteObject();
                    clientContext.ExecuteQuery();
                }

                // Solve layout and create new page
                Microsoft.SharePoint.Client.ListItem pageLayout = clientContext.Web.GetPageLayoutListItemByName("ContosoLinksRight.aspx");
                PublishingWeb             pWeb = PublishingWeb.GetPublishingWeb(clientContext, clientContext.Web);
                PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
                publishingPageInfo.Name = "demo.aspx";
                publishingPageInfo.PageLayoutListItem = pageLayout;
                PublishingPage publishingPage = pWeb.AddPublishingPage(publishingPageInfo);
                if (pages.ForceCheckout || pages.EnableVersioning)
                {
                    publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                    publishingPage.ListItem.File.Publish(string.Empty);
                    if (pages.EnableModeration)
                    {
                        publishingPage.ListItem.File.Approve(string.Empty);
                    }
                }
                clientContext.ExecuteQuery();

                lblStatus1.Text = string.Format("New content type created, page layouts uploaded and new page created to the <a href='{0}'>host web</a>.", spContext.SPHostUrl.ToString() + "/pages/demo.aspx");
            }
        }
Ejemplo n.º 8
0
        private void MigrateOnePage(SPSite site, SPWeb web, SPList list, SPListItem item, String username, String password)
        {
            string remotePageURL      = item.WBxGetColumnAsString(REMOTE_PAGE_URL);
            string newLogicalLocation = item.WBxGetColumnAsString(NEW_LOGICAL_LOCATION);
            string siteOrPage         = item.WBxGetColumnAsString(SITE_OR_PAGE);
            string localPageURL       = item.WBxGetColumnAsString(LOCAL_PAGE_URL);
            string resultMessage      = "";

            if (newLogicalLocation == "")
            {
                MigrationError(item, "There was no new logical location set!");
                return;
            }

            WBLogging.Migration.HighLevel("Starting MigrateOnePage() for newLogicalLocation : " + newLogicalLocation);

            if (siteOrPage == "")
            {
                MigrationError(item, "The 'Site or Page' value wasn't set!");
                return;
            }

            if (localPageURL == "")
            {
                localPageURL = MakeLocalPageURL(newLogicalLocation, siteOrPage);
                item.WBxSetColumnAsString(LOCAL_PAGE_URL, localPageURL);
            }

            string remotePageURLToUse = remotePageURL.Replace("/alfresco/web/izzi/", "/alfresco/service/mizzi/");

            string localSPWebRelativeURL = newLogicalLocation;

            if (siteOrPage == PAGE)
            {
                localSPWebRelativeURL = WBUtils.GetParentPath(newLogicalLocation, false);
            }

            if (remotePageURL != "")
            {
                WBLogging.Migration.Verbose("Migrating remote -> local: " + remotePageURL + " -> " + localPageURL);
            }
            else
            {
                WBLogging.Migration.Verbose("Creating new local unmapped site: " + localPageURL);
            }

            SPWeb localWeb = null;

            try
            {
                string pageTitle    = item.WBxGetColumnAsString("Title");
                string pageTemplate = "";

                if (remotePageURL != "")
                {
                    pageTitle     = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TITLE=true", username, password);
                    item["Title"] = pageTitle;

                    pageTemplate        = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TEMPLATE=true", username, password);
                    item[PAGE_TEMPLATE] = pageTemplate;
                }


                if (remotePageURL != "" && pageTemplate != "izziThreeColumn.ftl")
                {
                    resultMessage = "Not migrated yet (due to unhandled template)";
                }
                else
                {
                    bool newSiteCreated = false;

                    localWeb = site.OpenWeb(localSPWebRelativeURL);

                    if (!localWeb.Exists)
                    {
                        // OK let's try to get the parent web:
                        string parentURL = WBUtils.GetParentPath(localSPWebRelativeURL, false);
                        string childName = WBUtils.GetLastNameInPath(localSPWebRelativeURL);

                        WBLogging.Migration.Verbose("Trying to find parent URL: " + parentURL);

                        using (SPWeb parentWeb = site.OpenWeb(parentURL))
                        {
                            if (parentWeb.Exists)
                            {
                                if (pageTitle == "")
                                {
                                    pageTitle     = childName.WBxToUpperFirstLetter();
                                    item["Title"] = pageTitle;
                                }
                                localWeb       = parentWeb.Webs.Add(childName, pageTitle, pageTitle, 1033, "CMSPUBLISHING#0", true, false);
                                newSiteCreated = true;
                            }
                            else
                            {
                                WBLogging.Migration.Verbose("Couldn't find parente web site - Don't know how to handle this situation.");
                                resultMessage = "Couldn't find the parent web site";
                            }
                        }
                    }

                    if (localWeb.Exists)
                    {
                        if (localWeb.HasUniqueRoleAssignments)
                        {
                            localWeb.ResetRoleInheritance();
                            localWeb.Update();
                        }

                        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(localWeb);

                        PageLayout layout = WBUtils.GetPageLayout(publishingWeb, "LBI Standard page layout");

                        if (layout == null)
                        {
                            MigrationError(item, "Didn't find the page layout!!");
                            return;
                        }

                        SPFile         pageFile = null;
                        PublishingPage page     = null;

                        // If this location is for a site then we get the default page:
                        if (siteOrPage == SITE)
                        {
                            pageFile = publishingWeb.DefaultPage;
                            page     = PublishingPage.GetPublishingPage(pageFile.Item);
                        }
                        else
                        {
                            // Otherwise we have to get or create a named page:
                            string pageName = WBUtils.GetLastNameInPath(newLogicalLocation) + ".aspx";

                            SPListItem pageItem = WBUtils.FindItemByColumn(site, publishingWeb.PagesList, WBColumn.Name, pageName);
                            if (pageItem != null)
                            {
                                page = PublishingPage.GetPublishingPage(pageItem);
                            }
                            else
                            {
                                // We couldn't find the page so we'll add it as a new page:
                                page = publishingWeb.AddPublishingPage(pageName, layout);
                            }

                            pageFile = page.ListItem.File;

                            string urlFromItem = "http://sp.izzi" + page.ListItem.File.ServerRelativeUrl;
                            if (localPageURL != urlFromItem)
                            {
                                MigrationError(item, "The generated names don't match: localPageURL | urlFromItem : " + localPageURL + " | " + urlFromItem);
                                return;
                            }
                        }

                        // So we'll update the content if we're migrating an izzi page or it's the first time
                        // creation of a new local page:
                        if (remotePageURL != "" || newSiteCreated)
                        {
                            string pageText = "This page is not being migrated so needs to be edited locally.";
                            if (remotePageURL != "")
                            {
                                pageText = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TEXT=true", username, password);
                                pageText = ProcessPageText(site, list, pageText);
                            }

                            if (pageFile.CheckOutType == SPFile.SPCheckOutType.None)
                            {
                                WBLogging.Migration.Verbose("Checking out the pageFile");
                                pageFile.CheckOut();
                            }
                            else
                            {
                                WBLogging.Migration.Verbose("No need to check out the pageFile");
                            }

                            if (newSiteCreated)
                            {
                                page.Layout = layout;
                                page.Update();
                            }

                            pageFile.Item["Page Content"] = pageText;
                            pageFile.Item["Title"]        = pageTitle;


                            pageFile.Item.Update();
                            pageFile.Update();


                            pageFile.CheckIn("Checked in programmatically");
                            pageFile.Publish("Published programmatically");

                            WBLogging.Migration.Verbose("Publisehd migrated page: " + localPageURL);
                        }
                    }
                    else
                    {
                        WBLogging.Migration.Unexpected("Wasn't able to find or create the local web: " + localSPWebRelativeURL);
                        resultMessage += " Wasn't able to find or create the local web: " + localSPWebRelativeURL;
                    }
                }
            }
            catch (Exception error)
            {
                WBLogging.Migration.Unexpected("There was an error: " + error.Message + " Tried with remote | local : " + remotePageURL + " | " + localPageURL);
                resultMessage = "There was an error: " + error.Message + " Tried with remote | local : " + remotePageURL + " | " + localPageURL;
            }
            finally
            {
                if (localWeb != null)
                {
                    localWeb.Dispose();
                }
            }

            if (resultMessage == "")
            {
                resultMessage        = "Processed OK";
                item[LAST_MIGRATION] = DateTime.Now;
            }


            WBLogging.Migration.Verbose("Result message : " + resultMessage);

            item.WBxSetColumnAsString(RESULT_MESSAGE, resultMessage);
            item.Update();

            WBLogging.Migration.HighLevel("Finished MigrateOnePage() for newLogicalLocation : " + newLogicalLocation);
        }
Ejemplo n.º 9
0
        private static void CreatePublishingPage2013(ClientContext ctx, Web web, XElement xPage)
        {
            Web webSite = web;

            ctx.Load(webSite);

            PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(ctx, webSite);

            ctx.Load(pubWeb);

            string pageName       = xPage.Attribute("Name").Value;
            string layoutPageName = xPage.Attribute("LayoutPageName").Value;
            string pageLibrary    = xPage.Attribute("PageLibrary").Value;

            if (pubWeb != null)
            {
                // Get library to hold new page

                List targetLibrary = webSite.Lists.GetByTitle(pageLibrary);

                ListItemCollection existingPages = targetLibrary.GetItems(CamlQuery.CreateAllItemsQuery());

                ctx.Load(existingPages, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pageName));
                ctx.ExecuteQuery();

                if (existingPages != null && existingPages.Count > 0)
                {
                    // Page already exists
                }
                else
                {
                    // Get publishing page layouts

                    List publishingLayouts = ctx.Web.Lists.GetByTitle("Master Page Gallery");

                    ListItemCollection layoutPages = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                    ctx.Load(layoutPages, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == layoutPageName));
                    ctx.ExecuteQuery();

                    ListItem layoutPage = layoutPages.Where(x => x.DisplayName == layoutPageName).FirstOrDefault();
                    ctx.Load(layoutPage);

                    // Create a publishing page

                    PublishingPageInformation newPublishingPageInfo = new PublishingPageInformation();
                    newPublishingPageInfo.Name = pageName;
                    newPublishingPageInfo.PageLayoutListItem = layoutPage;

                    PublishingPage newPublishingPage = pubWeb.AddPublishingPage(newPublishingPageInfo);

                    newPublishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                    newPublishingPage.ListItem.File.Publish(string.Empty);
                    newPublishingPage.ListItem.File.Approve(string.Empty);

                    ctx.Load(newPublishingPage);
                    ctx.Load(newPublishingPage.ListItem.File, obj => obj.ServerRelativeUrl);

                    ctx.ExecuteQuery();
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter Site Address: ");
            string siteUrl      = Console.ReadLine();
            bool   siteOnline   = false;
            string siteUser     = "";
            string sitePassword = "";
            string siteDomain   = "";

            if (siteUrl.Contains(".sharepoint.com"))
            {
                Console.WriteLine("This site is SharePoint Online Right ? (Y/N): ");
                string OnlineAnswer = Console.ReadLine();

                if (OnlineAnswer.ToUpper() == "Y")
                {
                    siteOnline = true;
                }
            }

            if (siteOnline)
            {
                Console.WriteLine("Please Enter Site Login User Email Address: ");
                siteUser = Console.ReadLine();

                Console.WriteLine("Please Enter Site Login User Password: "******"Please Enter Site Login User Domain Name: ");
                siteDomain = Console.ReadLine();

                Console.WriteLine("Please Enter Site Login User Name: ");
                siteUser = Console.ReadLine();

                Console.WriteLine("Please Enter Site Login User Password: "******"Please Enter Master Page Gallery Name: ");
            string siteMasterPageGallery = Console.ReadLine();

            Console.WriteLine("Please Enter Create Publishing Page Content Type Display Name: ");
            string pageContentType = Console.ReadLine();

            Console.WriteLine("Please Enter Create Publishing Page Name: ");
            string pageName = Console.ReadLine();

            Console.WriteLine("Do You Have Add Page Field Value (Y/N): ");
            string addPageValuAnswer  = Console.ReadLine();
            bool   addPageValue       = false;
            string addPageValueString = "";

            if (addPageValuAnswer.ToUpper() == "Y")
            {
                addPageValue = true;
                Console.WriteLine("Please Enter Page Field Data ( ':' Separator Using For Field Name And Value, ';' Separator Using For Each Field Data ): ");
                Console.WriteLine("For Example ---> Title:TestPage;Comments:TestPage Comments ");
                Console.WriteLine("");
                addPageValueString = Console.ReadLine();
            }

            Console.WriteLine("Please Wait Start Create Process....");

            ClientContext  clientContext  = null;
            PublishingPage publishingPage = null;
            Web            web            = null;

            try
            {
                clientContext = new ClientContext(siteUrl);

                if (siteOnline)
                {
                    clientContext.AuthenticationMode = ClientAuthenticationMode.Default;

                    string password = sitePassword;
                    System.Security.SecureString passwordChar = new System.Security.SecureString();
                    foreach (char ch in password)
                    {
                        passwordChar.AppendChar(ch);
                    }

                    clientContext.Credentials = new SharePointOnlineCredentials(siteUser, passwordChar);
                }
                else
                {
                    clientContext.Credentials = new NetworkCredential(siteUser, sitePassword, siteDomain);
                }

                web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("This Site Connect Error Please Check Your Information And Try Again");
                Console.WriteLine("Error Message: " + ex.Message);
                Console.ReadLine();
                Environment.Exit(0);
            }

            try
            {
                Console.WriteLine("This Site Connection Success....");
                Console.WriteLine("Please Wait Create Publishing Page.....");

                List publishingLayouts      = clientContext.Site.RootWeb.Lists.GetByTitle(siteMasterPageGallery);
                ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                clientContext.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pageContentType));
                clientContext.ExecuteQuery();
                ListItem layout = allItems.Where(x => x.DisplayName == pageContentType).FirstOrDefault();
                clientContext.Load(layout);

                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(clientContext, web);
                clientContext.Load(publishingWeb);

                PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
                publishingPageInfo.Name = pageName.Contains(".aspx") ? pageName : pageName + ".aspx";
                publishingPageInfo.PageLayoutListItem = layout;

                publishingPage = publishingWeb.AddPublishingPage(publishingPageInfo);

                clientContext.Load(publishingPage);
                clientContext.Load(publishingPage.ListItem.File);
                clientContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("This During Publishing Page Error Please Check Your Information And Try Again");
                Console.WriteLine("Error Message: " + ex.Message);
                Console.ReadLine();
                Environment.Exit(0);
            }

            Console.WriteLine("this Publishing Page Create Success....");

            if (addPageValue)
            {
                try
                {
                    Console.WriteLine("Please Wait Add Field Data Publishing Page....");

                    ListItem listItem = publishingPage.ListItem;

                    string[] dataArray = addPageValueString.Split(';');

                    foreach (string data in dataArray)
                    {
                        listItem[data.Split(':')[0]] = data.Split(':')[1];
                    }

                    listItem.Update();

                    publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                    publishingPage.ListItem.File.Publish(string.Empty);

                    clientContext.Load(publishingPage);

                    clientContext.ExecuteQuery();

                    Console.WriteLine("Tihs Publishing Page Add Field Data Success....");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("This During Publishing Page Add Field Data Error Please Check Your Information And Try Again");
                    Console.WriteLine("Error Message: " + ex.Message);
                    Console.ReadLine();
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("All Process Complete Success...");
            Console.ReadLine();
            Environment.Exit(0);
        }
        private void ProvisionFromStorage(ClientContext ctx, Web web, AppManifestBase manifest)
        {
            List wikiPagesLibrary       = null;
            List publishingPagesLibrary = null;

            if (Creators != null && Creators.Count > 0)
            {
                foreach (var fileCreator in Creators.Values)
                {
                    try
                    {
                        if (!FileExists(fileCreator, ctx, web, fileCreator.ForceOverwrite))
                        {
                            if ((fileCreator.ContentType != null && fileCreator.ContentType == "Wiki Page") || (fileCreator.ContentTypeId != null && fileCreator.ContentTypeId.StartsWith(WikiPageContentTypeId)))
                            {
                                OnNotify(ProvisioningNotificationLevels.Verbose, "Creating wiki page " + fileCreator.Url);
                                if (wikiPagesLibrary == null)
                                {
                                    wikiPagesLibrary = web.Lists.GetByTitle(fileCreator.List);
                                    ctx.Load(wikiPagesLibrary.RootFolder, f => f.ServerRelativeUrl);
                                    ctx.ExecuteQueryRetry();
                                }
                                var fileUrl = fileCreator.Url;
                                if (web.ServerRelativeUrl != "/")
                                {
                                    fileUrl = web.ServerRelativeUrl + fileUrl;
                                }

                                fileCreator.File = wikiPagesLibrary.RootFolder.Files.AddTemplateFile(fileUrl,
                                                                                                     TemplateFileType.WikiPage);
                                ctx.Load(fileCreator.File, f => f.ServerRelativeUrl);
                                ctx.ExecuteQueryRetry();
                                fileCreator.AddWikiOrPublishingPageWebParts(ctx, web, WikiPageContentFieldName);
                                fileCreator.Created = true;
                            }
                            else if (fileCreator.ContentTypeId != null && fileCreator.ContentTypeId.StartsWith(PublishingPageContentTypeId))
                            {
                                OnNotify(ProvisioningNotificationLevels.Verbose, "Creating publishing page " + fileCreator.Url);
                                if (publishingPagesLibrary == null)
                                {
                                    publishingPagesLibrary = web.Lists.GetByTitle(fileCreator.List);
                                    ctx.Load(publishingPagesLibrary.RootFolder, f => f.ServerRelativeUrl);
                                    ctx.ExecuteQueryRetry();
                                }
                                var fileUrl = fileCreator.Url;
                                if (web.ServerRelativeUrl != "/")
                                {
                                    fileUrl = web.ServerRelativeUrl + fileUrl;
                                }

                                var pageName   = fileCreator.ListItemFieldValues.Find(p => p.FieldName == "FileLeafRef")?.Value;
                                var pageLayout = fileCreator.ListItemFieldValues.Find(p => p.FieldName == "PublishingPageLayout")?.Value;


                                if (string.IsNullOrEmpty(pageName) || string.IsNullOrEmpty(pageLayout) || !pageLayout.Contains(", "))
                                {
                                    OnNotify(ProvisioningNotificationLevels.Verbose,
                                             $"Invalid publishing page data for {fileCreator.Url}! Skipping");
                                }
                                else
                                {
                                    try
                                    {
                                        pageLayout = pageLayout.Split(',')[0].Replace("{@WebUrl}", web.ServerRelativeUrl);
                                        var pageLayoutListItem =
                                            web.GetFileByServerRelativeUrl(pageLayout).ListItemAllFields;
                                        ctx.Load(pageLayoutListItem);
                                        PublishingPageInformation publishingPageInfo = new PublishingPageInformation()
                                        {
                                            Name               = pageName,
                                            Folder             = publishingPagesLibrary.RootFolder,
                                            PageLayoutListItem = pageLayoutListItem
                                        };
                                        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(ctx, web);
                                        fileCreator.File = publishingWeb.AddPublishingPage(publishingPageInfo).ListItem.File;
                                        ctx.Load(fileCreator.File, f => f.ServerRelativeUrl);
                                        ctx.ExecuteQueryRetry();
                                        fileCreator.AddWikiOrPublishingPageWebParts(ctx, web, PublishingPageContentFieldName);
                                        fileCreator.Created = true;
                                    }
                                    catch
                                    {
                                        OnNotify(ProvisioningNotificationLevels.Verbose,
                                                 $"Invalid publishing page data for {fileCreator.Url}! Unable to find page layout at {pageLayout}. If the page layout is in the manifest, ensure that it appears before the pages that depend on it. Skipping");
                                    }
                                }
                            }
                            else if ((fileCreator.ContentType != null && fileCreator.ContentType == "Web Part Page") || (fileCreator.ContentTypeId != null && fileCreator.ContentTypeId.StartsWith(BasicPageContentTypeId)))
                            {
                                OnNotify(ProvisioningNotificationLevels.Verbose,
                                         "Creating web part page " + fileCreator.Url);
                                var file = GetFileFromStorage(manifest, fileCreator);

                                file             = fileCreator.PrepareFile(file, ctx, web, true);
                                fileCreator.File = UploadFile(ctx, web, fileCreator.List, file, fileCreator.Url);
                                ctx.Load(fileCreator.File, f => f.ServerRelativeUrl);
                                ctx.ExecuteQueryRetry();
                                fileCreator.AddWebPartPageWebParts(ctx, web);
                                fileCreator.Created = true;
                            }
                            else
                            {
                                OnNotify(ProvisioningNotificationLevels.Verbose, "Creating file " + fileCreator.Url);
                                var file = GetFileFromStorage(manifest, fileCreator);
                                if (!fileCreator.IsBinary)
                                {
                                    file = fileCreator.PrepareFile(file, ctx, web, fileCreator.ContentType != null && fileCreator.ContentType == "Workflow");
                                }
                                fileCreator.File = UploadFile(ctx, web, fileCreator.List, file, fileCreator.Url);
                                ctx.Load(fileCreator.File, f => f.ServerRelativeUrl);
                                fileCreator.Created = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        OnNotify(ProvisioningNotificationLevels.Normal,
                                 "Error creating file " + fileCreator.RelativeFilePath + " | " + ex);
                        Trace.TraceError("Error creating file " + fileCreator.RelativeFilePath + " | " + ex);
                        throw;
                    }
                }

                if (!ctx.Web.IsPropertyAvailable("AppInstanceId"))
                {
                    ctx.Load(ctx.Web, w => w.AppInstanceId);
                    ctx.ExecuteQueryRetry();
                }
                if (ctx.Web.AppInstanceId == default(Guid))
                {
                    ApplySecurity(ctx);
                }

                foreach (var key in Creators.Keys)
                {
                    OnNotify(ProvisioningNotificationLevels.Verbose, "Setting properties for " + Creators[key].Url);
                    Creators[key].SetProperties(ctx, web);
                }
                ctx.ExecuteQueryRetry();
            }
        }