/// <summary>
 /// Called when a PublishingPage object is enumerated.
 /// </summary>
 /// <param name="site">The site.</param>
 /// <param name="web">The web.</param>
 /// <param name="page">The page.</param>
 protected void OnPublishingPageEnumerated(SPSite site, SPWeb web, PublishingPage page)
 {
     if (PublishingPageEnumerated != null)
     {
         PublishingPageEnumerated(this, new PublishingPageEventArgs(site, web, page));
     }
 }
 /// <summary>
 /// Update, check-in, publish and approve a page with a check-in message.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="message">The message.</param>
 public void UpdateCheckInPublishApprove(PublishingPage page, string message)
 {
     page.Update();
     page.CheckIn(message);
     page.ListItem.File.Publish(message);
     page.ListItem.File.Approve(message);
 }
Exemplo n.º 3
0
        private void CreatePartnerTabbedPage(SPWeb web, SPList sitesList)
        {
            // Create a new page for listing Partner Site Collections
            if (PublishingWeb.IsPublishingWeb(web))
            {
                PublishingWeb            pubWeb           = PublishingWeb.GetPublishingWeb(web);
                PublishingPageCollection availablePages   = pubWeb.GetPublishingPages();
                PublishingPage           partnerSitesPage = availablePages[Constants.PartnerSitesPageUrl];

                if (partnerSitesPage == null)
                {
                    // The Partner Sites page should be based on the same layout as the top sites page.
                    PublishingPage topSitesPage = availablePages[Constants.TopSitesPageUrl];
                    partnerSitesPage = availablePages.Add(Constants.PartnerSitesFileName, topSitesPage.Layout);
                    partnerSitesPage.ListItem[titleFieldId] = Constants.PartnerSitesTile;
                    // We can not use the Field Id of the the Description field, because it is not static.
                    partnerSitesPage.ListItem[Constants.DescriptionField] = Resources.PartnerSitePageDescription;
                    partnerSitesPage.Update();
                    SPFile partnerSitesPageFile = web.GetFile(partnerSitesPage.Url);

                    AddListViewWebPartToPage(sitesList, partnerSitesPage, partnerSitesPageFile);

                    // Add a tab to the Tabs control.
                    SPListItem newTab = web.Lists[Constants.TabsList].Items.Add();
                    newTab[Constants.TabNameField] = Constants.PartnersTabName;
                    newTab[Constants.PageField]    = Constants.PartnerSitesFileName;
                    newTab[Constants.TooltipField] = Constants.PartnerSitesTooltip;
                    newTab.Update();
                }
            }
        }
Exemplo n.º 4
0
        private static void RemovePublishingPage(SPPublishing.PublishingPage publishingPage, PublishingPage page, ClientContext ctx, Web web)
        {
            if (publishingPage != null && publishingPage.ServerObjectIsNull.Value == false)
            {
                if (!web.IsPropertyAvailable("RootFolder"))
                {
                    web.Context.Load(web.RootFolder);
                    web.Context.ExecuteQueryRetry();
                }

                if (page.Overwrite)
                {
                    if (page.WelcomePage && web.RootFolder.WelcomePage.Contains(page.FileName + ".aspx"))
                    {
                        //set the welcome page to a Temp page to allow remove the page
                        web.RootFolder.WelcomePage = "home.aspx";
                        web.RootFolder.Update();
                        web.Update();

                        ctx.Load(publishingPage);
                        ctx.ExecuteQuery();
                    }

                    publishingPage.ListItem.DeleteObject();
                    ctx.ExecuteQuery();
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 5
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            PublishingWeb pWeb           = PublishingWeb.GetPublishingWeb(site.RootWeb);
            bool          pageNotCreated = !pWeb.GetPublishingPages().Cast <PublishingPage>().Any(p => p.Name == pageName);

            if (pageNotCreated)
            {
                //если такой страницы еще нет - создаем ее
                PublishingPage pPage = pWeb.GetPublishingPages().Add(pageName, null);

                pPage.CheckOut();

                using (Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager wpManager = site.RootWeb.GetLimitedWebPartManager(pPage.Url, PersonalizationScope.Shared))
                {
                    ResultScriptWebPart searchResults = GetImportedWebPart(site, wpName) as ResultScriptWebPart;
                    searchResults.Title      = wpTitle;
                    searchResults.ChromeType = PartChromeType.None;

                    wpManager.AddWebPart(searchResults, "Top", 0);
                }

                pPage.CheckIn(string.Empty);
            }
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Renders the metatag HTML code.
        /// </summary>
        /// <param name="writer">HtmlTextWriter to write to.</param>
        public void Render(HtmlTextWriter writer, PublishingPage publishingPage)
        {
            string code  = String.Empty;
            string value = String.Empty;

            if (publishingPage.Fields.ContainsField(this.ColumnTitle))
            {
                if (publishingPage.ListItem[this.ColumnTitle] != null)
                {
                    // Format DateTime fields
                    if (this.ColumnType == SPFieldType.DateTime)
                    {
                        value = this.FormatDate((DateTime)publishingPage.ListItem[this.ColumnTitle]);
                    }
                    else
                    {
                        value = System.Web.HttpUtility.HtmlEncode(publishingPage.ListItem[this.ColumnTitle].ToString());
                    }

                    code = String.Format("<meta name=\"{0}\" {1} content=\"{2}\" />", this.Name, this.GenerateAllAttributes(), value);
                }
            }
            else
            {
                if (this.DefaultContent != null)
                {
                    value = this.ReplaceDefaultContent(this.DefaultContent);
                    code  = String.Format("<meta name=\"{0}\" {1} content=\"{2}\" />", this.Name, this.GenerateAllAttributes(), value);
                }
            }

            writer.WriteLine(code);
        }
Exemplo n.º 8
0
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            // allow third party applications to override the title of the current node in the breadcrumb
            SPCLF3.Master_Pages.CLF3PublishingMaster masterPage = (SPCLF3.Master_Pages.CLF3PublishingMaster) this.Page.Master;
            if (String.IsNullOrEmpty(masterPage.PageTitle))
            {
                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
                    writer.WriteLine(publishingPage.Title);
                }
                else if (SPContext.Current.ListItem != null)
                {
                    writer.Write(SPContext.Current.ListItem.Title);
                }
                else if (SPContext.Current.List != null)
                {
                    writer.Write(SPContext.Current.List.Title);
                }
            }
            else
            {
                writer.WriteLine(masterPage.PageTitle);
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            string htmlOutput = string.Empty;

            try
            {
                // setup the outer wrappers
                htmlOutput += "<div class=\"wet-boew-menubar mb-mega\"><div><ul class=\"mb-menu\" data-ajax-replace=\"";

                if (SPContext.Current.Web.Locale.TwoLetterISOLanguageName == "en")
                {
                    htmlOutput += "/Navigation/menu-eng.txt\">";
                }
                else
                {
                    htmlOutput += "/Navigation/menu-fra.txt\">";
                }

                string langWeb = string.Empty;
                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    // figure out our language of the current label
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);

                    if (publishingPage.PublishingWeb.Label != null)
                    {
                        langWeb = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "eng" : "fra";
                    }
                }
                else
                {
                    string cultISO = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
                    langWeb = (cultISO == "en") ? "eng" : "fra";
                }

                string webUrl = SPContext.Current.Web.Url;

                //TODO - Remove this debug logic;
#if DEBUG
                if (webUrl.Contains("l41-106306"))
                {
                    webUrl = webUrl.Replace("l41-106306", "localhost");
                }
#endif

                using (SPSite site = new SPSite(webUrl))
                {
                    htmlOutput += renderTopLevelLink(langWeb);

                    // setup the outer wrappers
                    htmlOutput += "</ul></div></div>";

                    writer.Write(htmlOutput);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message + " " + ex.StackTrace);
            }
        }
Exemplo n.º 10
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                string langWeb = string.Empty;

                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    // figure out our language of the current label
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);

                    if (publishingPage.PublishingWeb.Label != null)
                    {
                        langWeb = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "eng" : "fra";
                    }
                }
                else
                {
                    string cultISO = "";
                    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/eng/"))
                    {
                        cultISO = "en";
                    }
                    else
                    {
                        cultISO = "fr";
                    }
                    langWeb = (cultISO == "en") ? "eng" : "fra";
                }

                HtmlGenericControl pnlSearch = new HtmlGenericControl("div");
                pnlSearch.Attributes.Add("class", "form-group");

                txtSearchBox = new TextBox()
                {
                    CssClass = "form-control",
                };
                txtSearchBox.Attributes.Add("type", "search");
                txtSearchBox.Attributes.Add("size", "27");
                txtSearchBox.MaxLength = 150;
                txtSearchBox.Style.Add("margin-right", "5px");
                pnlSearch.Controls.Add(txtSearchBox);

                this.Controls.Add(pnlSearch);

                HtmlButton btnSearch = new HtmlButton();
                btnSearch.Attributes.Add("class", "btn btn-default");
                btnSearch.Attributes.Add("type", "submit");
                btnSearch.InnerText    = (langWeb == "fra") ? "Recherche" : "Search";
                btnSearch.ServerClick += btnSearch_ServerClick;

                this.Controls.Add(btnSearch);
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 11
0
        protected override void Render(HtmlTextWriter writer)
        {
            string htmlOutput = string.Empty;

            try
            {
                // setup the outer wrappers
                htmlOutput += "<div class=\"wet-boew-menubar mb-mega\"><div><ul class=\"mb-menu\" data-ajax-replace=\"";

                if (SPContext.Current.Web.Locale.TwoLetterISOLanguageName == "en")
                {
                    htmlOutput += "/Lists/TopNavigation/menu-eng.txt\">";
                }
                else
                {
                    htmlOutput += "/Lists/TopNavigation/menu-fra.txt\">";
                }

                string langWeb = string.Empty;
                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    // figure out our language of the current label
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);

                    if (publishingPage.PublishingWeb.Label != null)
                    {
                        langWeb = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "eng" : "fra";
                    }
                }
                else
                {
                    string cultISO = "";
                    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/eng/"))
                    {
                        cultISO = "en";
                    }
                    else
                    {
                        cultISO = "fr";
                    }
                    langWeb = (cultISO == "en") ? "eng" : "fra";
                }

                string webUrl = SPContext.Current.Web.Url;
                using (SPSite site = new SPSite(webUrl))
                {
                    htmlOutput += renderTopLevelLink(langWeb);

                    // setup the outer wrappers
                    htmlOutput += "</ul></div></div>";

                    writer.Write(htmlOutput);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message + " " + ex.StackTrace);
            }
        }
        // method for creating publising page
        private string CreatePublishingPage(string pageName, string pageLayoutName, bool isLandingPage)
        {
            string createdPageURL = string.Empty;

            // elevated privilages as not all user will have permission to create a new page
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // get current web
                SPWeb oWeb                  = SPContext.Current.Web;
                string fullPageUrl          = string.Empty;
                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(oWeb);
                /* Get the publishing web page collection list. */
                PublishingPageCollection publishingPageCollection = publishingWeb.GetPublishingPages();
                //GetPageLayoutName(application);
                if (!string.IsNullOrEmpty(pageLayoutName))
                {
                    /* Search for the page layout for creating the new page */
                    List <PageLayout> layouts = new List <PageLayout>(publishingWeb.GetAvailablePageLayouts());
                    PageLayout pageLayout     = layouts.Find(
                        delegate(PageLayout l)
                    {
                        return(l.Name.Equals(pageLayoutName, StringComparison.CurrentCultureIgnoreCase));
                    });
                    /*page layout exists*/
                    if (pageLayout != null)
                    {
                        PublishingPage newPage = null;
                        newPage       = publishingPageCollection.Add(pageName + ".aspx", pageLayout);
                        newPage.Title = pageName;
                        newPage.Update();

                        SPList li = newPage.ListItem.ParentList;

                        if (li.EnableModeration == false)
                        {
                            li.EnableModeration = true;
                            li.Update();
                        }
                        newPage.CheckIn("page checked in");
                        newPage.ListItem.File.Publish("page published");
                        newPage.ListItem.File.Approve("page approved");
                        /* Set newly created page as a welcome page */
                        if (isLandingPage == true)
                        {
                            fullPageUrl               = oWeb.Url + "/Pages/" + pageName + ".aspx";
                            SPFile fileNew            = publishingWeb.Web.GetFile(fullPageUrl);
                            publishingWeb.DefaultPage = fileNew;
                        }
                        publishingWeb.Update();

                        createdPageURL = newPage.Uri.AbsoluteUri.ToString();
                    }
                }
            });

            // return new page url
            return(createdPageURL);
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
            string         langWeb        = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "eng" : "fra";

            string searchCentreURL = SPContext.Current.Site.RootWeb.AllProperties["SRCH_ENH_FTR_URL"].ToString();

            Response.Redirect(searchCentreURL + "/results.aspx?k=" + txtSearch.Text, true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Creates the page.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="pageName">Name of the page.</param>
 /// <param name="title">The title.</param>
 /// <param name="layoutName">Name of the layout.</param>
 /// <param name="fieldDataCollection">The field data collection.</param>
 public static string CreatePage(string url, string pageName, string title, string layoutName, Dictionary <string, string> fieldDataCollection, bool test)
 {
     using (SPSite site = new SPSite(url))
         using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)])
         {
             PublishingPage page = CreatePage(web, pageName, title, layoutName, fieldDataCollection, test);
             return(site.MakeFullUrl(page.Url));
         }
 }
Exemplo n.º 15
0
        public static void AddWebPartsToPage(ClientContext ctx)
        {
            PublishingPage        page   = ctx.Web.GetPublishingPage("HomePage.aspx");
            File                  file   = page.ListItem.File;
            LimitedWebPartManager lwpm   = file.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
            WebPartDefinition     webDef = lwpm.ImportWebPart(WebPartStrings.ProductSearchWP);

            lwpm.AddWebPart(webDef.WebPart, "TopZone", 1);
            ctx.ExecuteQuery();
        }
Exemplo n.º 16
0
        private static SPFile CreateNewWelcomePage(SPWeb currentWeb, PublishingWeb publishingWeb, SPFile defaultPage)
        {
            PageLayout     welcomeLayout = publishingWeb.GetAvailablePageLayouts(ContentTypeId.WelcomePage)[0];
            PublishingPage welcomePage   = publishingWeb.GetPublishingPages().Add(DefaultFileName, welcomeLayout);

            defaultPage = currentWeb.GetFile(welcomePage.Url);
            publishingWeb.DefaultPage = defaultPage;
            publishingWeb.Update();
            //defaultPage.MoveTo("default.aspx", true);
            return(defaultPage);
        }
Exemplo n.º 17
0
 protected override void Render(HtmlTextWriter writer)
 {
     if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
     {
         // Generate each metatag
         PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
         foreach (MetaTag metaTag in PageMetadata.GetCustomMetaTags())
         {
             metaTag.Render(writer, publishingPage);
         }
     }
 }
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            // allow third party applications to override the title of the current node in the breadcrumb
            WET.Theme.Intranet.Master_Pages.WETIntranetPublishingMaster masterPage = (WET.Theme.Intranet.Master_Pages.WETIntranetPublishingMaster) this.Page.Master;
            if (String.IsNullOrEmpty(masterPage.PageTitle))
            {
                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
                    writer.WriteLine(publishingPage.Title);
                }
                else if (SPContext.Current.ListItem != null)
                {
                    try
                    {
                        writer.Write(SPContext.Current.ListItem.Title);
                    }
                    catch
                    {
                        try
                        {
                            writer.Write(SPContext.Current.ListItem.DisplayName);
                        }
                        catch (Exception ex)
                        {
                            WET.Theme.Intranet.Objects.Logger.WriteLog("Page Title:" + ex.Message);
                        }
                    }
                }
                else if (SPContext.Current.List != null)
                {
                    writer.Write(SPContext.Current.List.Title);
                }
                else if (HttpContext.Current.Request != null)
                {
                    string curUrl = HttpContext.Current.Request.Url.ToString();
                    string fileNameNoExtension = curUrl.Split('/')[curUrl.Split('/').Length - 1].Split('.')[0];
                    string fakeTitle           = char.ToUpper(fileNameNoExtension[0]) + fileNameNoExtension.ToLower().Substring(1);
                    writer.Write(fakeTitle);
                }
                else
                {
                    writer.Write("Administrative Page");
                }
            }
            else
            {
                writer.WriteLine(masterPage.PageTitle);
            }
        }
Exemplo n.º 19
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);
        }
        private static string ExportToXml(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            string pageXml = null;

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageXml = ExportPublishingPage(page, context.Web, context).ToString();
            }

            return(pageXml);
        }
        private static Dictionary <string, string> GetProperties(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            Dictionary <string, string> pageProperties = new Dictionary <string, string>();

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageProperties = SharePointCommandServices.GetProperties(page);
            }

            return(pageProperties);
        }
Exemplo n.º 22
0
 private void EnsurePageCheckOut(PublishingPage page)
 {
     if (page.ListItem.ParentList.ForceCheckout)
     {
         // Only check out if we are forced to do so
         if (page.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
         {
             // Only check out if not already checked out
             page.CheckOut();
         }
         else
         {
             this.logger.Warn("Page " + page.Uri.AbsoluteUri + " is already checked out - skipping FolderMaker checkout.");
         }
     }
 }
Exemplo n.º 23
0
        protected override void Render(HtmlTextWriter writer)
        {
            string htmlOutput = string.Empty;

            try
            {
                langWeb = string.Empty;
                if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
                {
                    // figure out our language of the current label
                    PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);

                    if (publishingPage.PublishingWeb.Label != null)
                    {
                        langWeb = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "Eng" : "Fra";
                    }
                }
                else
                {
                    string cultISO = "";
                    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/eng/"))
                    {
                        cultISO = "en";
                    }
                    else
                    {
                        cultISO = "fr";
                    }
                    langWeb = (cultISO == "en") ? "Eng" : "Fra";
                }

                htmlOutput += "<nav class=\"wb-menu visible-md visible-lg wb-init wb-data-ajax-replace-inited wb-menu-inited wb-navcurr-inited\" id=\"wb-sm\" role=\"navigation\" typeof=\"SiteNavigationElement\" data-trgt=\"mb-pnl\">\r\n";
                htmlOutput += "<div class=\"pnl-strt container visible-md visible-lg nvbar\">\r\n";
                htmlOutput += "<h2>Topics menu</h2>\r\n";
                htmlOutput += "<div class=\"row\">\r\n";
                htmlOutput += "<ul class=\"list-inline menu\" role=\"menubar\">\r\n";
                htmlOutput += renderTopLevelLinks();
                htmlOutput += "</ul></div></div>";
                htmlOutput += "</nav>";

                writer.Write(htmlOutput);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message + " " + ex.StackTrace);
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Render this control to the output parameter specified.
 /// </summary>
 /// <param name="output"> The HTML writer to write out to </param>
 protected override void Render(HtmlTextWriter output)
 {
     //Create a link back to the root of the variation
     if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
     {
         PublishingPage page = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
         if (page != null)
         {
             try
             {
                 // handle the homelink when variations are enabled
                 if (page.PublishingWeb.Label != null)
                 {
                     output.Write(
                         "<a href=\"" +
                         page.PublishingWeb.Label.TopWebUrl +
                         "\" style=\"font-size:1.5em;\">" +
                         HttpContext.GetGlobalResourceObject("WET", "SiteTitleText", SPContext.Current.Web.Locale).ToString() +
                         "</a>"
                         );
                 }
                 else
                 {
                     // when variations are not enabled
                     output.Write(
                         "<a href=\"" + SPContext.Current.Site.RootWeb.Url + "\" style=\"font-size:1.5em;\">" +
                         HttpContext.GetGlobalResourceObject("WET", "SiteTitleText", SPContext.Current.Web.Locale).ToString() +
                         "</a>"
                         );
                 }
             }
             catch (Exception ex)
             {
                 Logger.WriteLog(ex.Message + " " + ex.StackTrace);
             }
         }
     }
     else
     {
         // when variations are not enabled
         output.Write(
             "<a href=\"" + SPContext.Current.Site.RootWeb.Url + "\" style=\"font-size:1.5em;\">" +
             HttpContext.GetGlobalResourceObject("WET", "SiteTitleText", SPContext.Current.Web.Locale).ToString() +
             "</a>"
             );
     }
 }
Exemplo n.º 25
0
        private static void AddListViewWebPartToPage(SPList sitesList, PublishingPage partnerSitesPage, SPFile partnerSitesPageFile)
        {
            ListViewWebPart listViewWebPart = new ListViewWebPart();

            listViewWebPart.ViewType   = ViewType.None;
            listViewWebPart.ListName   = sitesList.ID.ToString("B").ToUpper(CultureInfo.CurrentCulture);
            listViewWebPart.ViewGuid   = sitesList.Views[Constants.PartnerSitesView].ID.ToString("B").ToUpper(CultureInfo.CurrentCulture);
            listViewWebPart.Title      = Constants.PartnerSitesTile;
            listViewWebPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;

            SPLimitedWebPartManager webPartManager =
                partnerSitesPageFile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

            webPartManager.AddWebPart(listViewWebPart, Constants.LeftColumnZone, 1);
            webPartManager.Web.Dispose();
            partnerSitesPage.CheckIn(Constants.CheckInComment);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets a Publishing Page from any folder in the Pages library.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="fileLeafRef">The file leaf reference.</param>
        /// <param name="folder">The folder where to search the page.</param>
        /// <returns>The PublishingPage object, if any. Otherwise null.</returns>
        /// <exception cref="System.ArgumentNullException">fileLeafRef</exception>
        /// <exception cref="System.ArgumentException">fileLeafRef</exception>
        public static PublishingPage GetPublishingPage(this Web web, string fileLeafRef, Folder folder)
        {
            if (string.IsNullOrEmpty(fileLeafRef))
            {
                throw (fileLeafRef == null)
                  ? new ArgumentNullException(nameof(fileLeafRef))
                  : new ArgumentException(CoreResources.Exception_Message_EmptyString_Arg, nameof(fileLeafRef));
            }

            var context = web.Context as ClientContext;
            var pages   = web.GetPagesLibrary();

            // Get the language agnostic "Pages" library name
            context.Load(pages, p => p.RootFolder, p => p.ItemCount);
            context.ExecuteQueryRetry();

            if (pages != null && pages.ItemCount > 0)
            {
                var camlQuery = new CamlQuery
                {
                    FolderServerRelativeUrl = folder != null ? folder.ServerRelativeUrl : pages.RootFolder.ServerRelativeUrl,
                    ViewXml = $@"<View Scope='RecursiveAll'>  
                                    <Query> 
                                        <Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>{fileLeafRef}</Value></Eq></Where> 
                                    </Query> 
                                </View>"
                };

                var listItems = pages.GetItems(camlQuery);
                context.Load(listItems);
                context.ExecuteQueryRetry();

                if (listItems.Count > 0)
                {
                    var page = PublishingPage.GetPublishingPage(context, listItems[0]);
                    context.Load(page);
                    context.ExecuteQueryRetry();
                    return(page);
                }
            }

            return(null);
        }
Exemplo n.º 27
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);
        }
 /// <summary>
 /// Render this control to the output parameter specified.
 /// </summary>
 /// <param name="output"> The HTML writer to write out to </param>
 protected override void Render(HtmlTextWriter output)
 {
     //get the placeholder that holds the meta tag content
     if (SPContext.Current.ListItem != null && PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
     {
         PublishingPage page = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
         if (page != null)
         {
             string sLastModifiedDate = page.LastModifiedDate.ToString("yyyy-MM-dd");
             output.Write(sLastModifiedDate);
         }
     }
     else
     {
         if (SPContext.Current.Web.LastItemModifiedDate != null)
         {
             string sLastModifiedDate = SPContext.Current.Web.LastItemModifiedDate.ToString("yyyy-MM-dd");
             output.Write(sLastModifiedDate);
         }
     }
 }
Exemplo n.º 29
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();
                }
            }
        }
Exemplo n.º 30
0
        private static void AddWebpartsToPublishingPage(PublishingPage page, ClientContext ctx, Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr)
        {
            foreach (var wp in page.WebParts)
            {
                string wpContentsTokenResolved = wp.Contents;
                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);
                }
            }
        }
Exemplo n.º 31
0
        void btnSearch_ServerClick(object sender, EventArgs e)
        {
            EnsureChildControls();

            PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
            string         langWeb        = string.Empty;

            if (publishingPage != null)
            {
                langWeb = (publishingPage.PublishingWeb.Label.Title.Substring(0, 2).ToLower() == "en") ? "eng" : "fra";
            }
            else if (SPContext.Current.Web.Url.ToLower().Contains("/fra/"))
            {
                langWeb = "fra";
            }
            else
            {
                langWeb = "eng";
            }

            string searchCentreURL = string.Empty;

            if (SPContext.Current.Site.RootWeb.AllProperties["SRCH_ENH_FTR_URL"] != null)
            {
                searchCentreURL = SPContext.Current.Site.RootWeb.AllProperties["SRCH_ENH_FTR_URL"].ToString();
            }
            else
            {
                if (langWeb == "eng")
                {
                    searchCentreURL = SPContext.Current.Site.RootWeb.Url + "/" + langWeb + "/Search/Pages/results.aspx?k=" + txtSearchBox.Text;
                }
                else
                {
                    searchCentreURL = SPContext.Current.Site.RootWeb.Url + "/" + langWeb + "/Recherche/Pages/resultats.aspx?k=" + txtSearchBox.Text;
                }
            }
            this.Page.Response.Redirect(searchCentreURL, true);
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            if (web != null)
            {
                if (PublishingWeb.IsPublishingWeb(web))
                {
                    PublishingWeb  pubWeb = PublishingWeb.GetPublishingWeb(web);
                    PublishingPage page   = pubWeb.GetPublishingPages()[PartnerLandingPageUrl];

                    if (page == null)
                    {
                        SPContentTypeId contentTypeId     = new SPContentTypeId(welcomePageLayoutContentTypeId);
                        PageLayout[]    layouts           = pubWeb.GetAvailablePageLayouts(contentTypeId);
                        PageLayout      welcomePageLayout = layouts[0];

                        page = pubWeb.GetPublishingPages().Add(PartnerLandingPageFileName, welcomePageLayout);
                    }
                    else
                    {
                        page.CheckOut();
                    }

                    page.ListItem[titleFieldId]                  = PartnerLandingPageTile;
                    page.ListItem[DescriptionField]              = Resources.PageDescription;
                    page.ListItem[pageContentFieldId]            = Resources.PageContent;
                    page.ListItem[partnerSpecificContentFieldId] = Resources.PartnerSpecificContent;
                    page.Update();

                    SPFile welcomeFile = web.GetFile(page.Url);
                    pubWeb.DefaultPage = welcomeFile;
                    pubWeb.Update();

                    page.CheckIn(Resources.CheckInValue);
                }
            }
        }
Exemplo n.º 33
0
        public void EnsurePage_WhenUpdatingAPage_GivenNewPageLayoutInfo_ThenExistingPageUsesTheNewPageLayout()
        {
            using (var testScope = SiteTestScope.PublishingSite())
            {
                var pagesLibrary = testScope.SiteCollection.RootWeb.GetPagesLibrary();
                var folder       = pagesLibrary.RootFolder;

                // Prepare the two page layouts. These are default SharePoint page Layouts.
                var initialPageLayoutInfo = new PageLayoutInfo("ArticleLeft.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");
                var finalPageLayoutInfo   = new PageLayoutInfo("ArticleRight.aspx", "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");

                // Prepare the two page infos. This for one, better simulates running the same code twice, and second we can't change the page layout property directly.
                var pageFileName    = "TestPage";
                var initialPageInfo = new PageInfo(pageFileName, initialPageLayoutInfo);
                var updatedPageInfo = new PageInfo(pageFileName, finalPageLayoutInfo);

                using (var injectionScope = IntegrationTestServiceLocator.BeginLifetimeScope(testScope.SiteCollection))
                {
                    var pageHelper = injectionScope.Resolve <IPageHelper>();

                    // Act

                    // Ensure the page with the initial page layout
                    PublishingPage initialPage = pageHelper.EnsurePage(pagesLibrary, folder, initialPageInfo);

                    // Re ensure the same page with the final pageLayoutInfo
                    PublishingPage updatedPage = pageHelper.EnsurePage(pagesLibrary, folder, updatedPageInfo);

                    // Assert

                    // Make sure the page layout has truely changed.
                    Assert.AreNotEqual(initialPage.Layout.ServerRelativeUrl, updatedPage.Layout.ServerRelativeUrl, "Page layout url should not be the same on the inital page as the updated page.");

                    // Make sure we are truely talking about the same page.
                    Assert.AreEqual(initialPage.Url, updatedPage.Url, "The initial page and updated page should have the same url.");
                }
            }
        }
 internal PublishingPageEventArgs(SPSite site, SPWeb web, PublishingPage page)
     : base(site, web, page.ListItem.ParentList)
 {
     m_Page = page;
 }
Exemplo n.º 35
0
        private static void EnsurePageCheckInAndPublish(PublishingPage page)
        {
            if (page.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
            {
                // Only check in if already checked out
                page.CheckIn(string.Empty);
            }

            if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Draft)
            {
                // Create a major version (just like "submit for approval")
                page.ListItem.File.Publish(string.Empty);

                // Status should now be Pending. Approve to make the major version visible to the public.
                page.ListItem.File.Approve(string.Empty);
            }
            else if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
            {
                // Technically, major version already exists, we just need to approve in order for the major version to be published
                page.ListItem.File.Approve(string.Empty);
            }
        }
 /// <summary>
 /// Called when a PublishingPage object is enumerated.
 /// </summary>
 /// <param name="site">The site.</param>
 /// <param name="web">The web.</param>
 /// <param name="page">The page.</param>
 protected void OnPublishingPageEnumerated(SPSite site, SPWeb web, PublishingPage page)
 {
     if (PublishingPageEnumerated != null)
         PublishingPageEnumerated(this, new PublishingPageEventArgs(site, web, page));
 }
        private List<PublishingPage> GetPublishingPagesListFromConfiguration()
        {
            List<PublishingPage> pages = new List<PublishingPage>();

            XNamespace ns = "http://schemas.somecompany.com/PublishingPageProvisioningExtensibilityHandlerConfiguration";
            XDocument doc = XDocument.Parse(configurationXml);

            foreach (var p in doc.Root.Descendants(ns + "Page"))
            {
                PublishingPage page = new PublishingPage
                {
                    Title = p.Attribute("Title").Value,
                    Layout = p.Attribute("Layout").Value,
                    Overwrite = bool.Parse(p.Attribute("Overwrite").Value),
                    FileName = p.Attribute("FileName").Value,
                    Publish = bool.Parse(p.Attribute("Publish").Value)
                };

                if (p.Attribute("WelcomePage") != null)
                {
                    page.WelcomePage = bool.Parse(p.Attribute("WelcomePage").Value);
                }

                var pageContentNode = p.Descendants(ns + "PublishingPageContent").FirstOrDefault();
                if (pageContentNode != null)
                {
                    page.PublishingPageContent = pageContentNode.Attribute("Value").Value;
                }

                foreach (var wp in p.Descendants(ns + "WebPart"))
                {
                    PublishingPageWebPart publishingPageWebPart = new PublishingPageWebPart();

                    if (wp.Attribute("DefaultViewDisplayName") != null)
                    {
                        publishingPageWebPart.DefaultViewDisplayName = wp.Attribute("DefaultViewDisplayName").Value;
                    }

                    publishingPageWebPart.Order = uint.Parse(wp.Attribute("Order").Value);
                    publishingPageWebPart.Title = wp.Attribute("Title").Value;
                    publishingPageWebPart.Zone = wp.Attribute("Zone").Value;

                    string webpartContensts = wp.Element(ns + "Contents").Value;
                    publishingPageWebPart.Contents = webpartContensts.Trim(new[] { '\n', ' ' });

                    page.WebParts.Add(publishingPageWebPart);
                }

                Dictionary<string, string> properties = new Dictionary<string, string>();
                foreach (var property in p.Descendants(ns + "Property"))
                {
                    properties.Add(
                        property.Attribute("Name").Value,
                        property.Attribute("Value").Value);
                }
                page.Properties = properties;

                pages.Add(page);
            }

            return pages;
        }
Exemplo n.º 38
0
 private void EnsureWebpartsOnPage(PublishingPage publishingPage)
 {
     var pageWebPart = this.defaultPageWebPartIndex.GetDefaultWebPartsForPageUrl(publishingPage.Url);
     if (pageWebPart != null)
     {
         pageWebPart.AddWebPartsToPage(publishingPage);
     }
 }
Exemplo n.º 39
0
        private static void EnsurePageCheckInAndPublish(PageInfo pageinfo, PublishingPage page)
        {
            string comment = "Dynamite Ensure Creation";

            if (page.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
            {
                // Only check in if already checked out
                page.CheckIn(comment);
            }

            // Are we publishing this page or not ?
            if (pageinfo.IsPublished)
            {
                if (page.ListItem.ParentList.EnableModeration)
                {
                    if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Draft)
                    {
                        // Create a major version (just like "submit for approval")
                        page.ListItem.File.Publish(comment);

                        // Status should now be Pending. Approve to make the major version visible to the public.
                        page.ListItem.File.Approve(comment);
                    }
                    else if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
                    {
                        // Technically, major version already exists, we just need to approve in order for the major version to be published
                        page.ListItem.File.Approve(comment);
                    }
                }
                else if (page.ListItem.File.MinorVersion != 0)
                {
                    // Create a major version, No approval required for this case.
                    page.ListItem.File.Publish(comment);
                }
            }
        }
Exemplo n.º 40
0
 private void EnsurePageCheckOut(PublishingPage page)
 {
     if (page.ListItem.ParentList.ForceCheckout)
     {
         // Only check out if we are forced to do so
         if (page.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
         {
             // Only check out if not already checked out
             page.CheckOut();
         }
         else
         {
             this.logger.Warn("Page " + page.Uri.AbsoluteUri + " is already checked out - skipping FolderMaker checkout.");
         }
     }
 }
Exemplo n.º 41
0
        private static void AddWebpartsToPublishingPage(PublishingPage page, ClientContext ctx, Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr)
        {
            foreach (var wp in page.WebParts)
            {
                string wpContentsTokenResolved = wp.Contents;
                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);
                }
            }
        }
Exemplo n.º 42
0
        /// <summary>
        /// Renders the metatag HTML code.
        /// </summary>
        /// <param name="writer">HtmlTextWriter to write to.</param>
        public void Render(HtmlTextWriter writer, PublishingPage publishingPage)
        {
            string code = String.Empty;
            string value = String.Empty;

            if (publishingPage.Fields.ContainsField(this.ColumnTitle))
            {
                if (publishingPage.ListItem[this.ColumnTitle] != null)
                {

                    // Format DateTime fields
                    if (this.ColumnType == SPFieldType.DateTime)
                        value = this.FormatDate((DateTime)publishingPage.ListItem[this.ColumnTitle]);
                    else
                        value = System.Web.HttpUtility.HtmlEncode(publishingPage.ListItem[this.ColumnTitle].ToString());

                    code = String.Format("<meta name=\"{0}\" {1} content=\"{2}\" />", this.Name, this.GenerateAllAttributes(), value);
                }
            }
            else
            {
                if (this.DefaultContent != null)
                {
                    value = this.ReplaceDefaultContent(this.DefaultContent);
                    code = String.Format("<meta name=\"{0}\" {1} content=\"{2}\" />", this.Name, this.GenerateAllAttributes(), value);
                }
            }

            writer.WriteLine(code);
        }