+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Duplicate Page Group

Duplicate Page Group

21 posts, 0 answered
  1. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    12 Apr 2010
    Link to this post
    I am looking to add a new LinkButton to the SiteMapPanel.ascx UserControl to duplicate page groups.

    I need the ability to only enable the LinkButton when a Page Group has been selected in the TreeView and I need help on where to access the Post Back function the LinkButton creates so I can write my custom code.

    This is what I have so far to the control:

    <li class="PageDuplicate">
                <asp:LinkButton ID="LinkButton6" CommandName="DuplicatePageGroup" Text="Duplicate Page Group" ToolTip="Duplicate Page Group" runat="server"></asp:LinkButton>
            </li>

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Apr 2010
    Link to this post
    Hello mcpdinkansas,

    Subscribe for Page_Load of SiteMapPanel.ascx and get the selected node. Then check the page type and hide the desired links

    public void Page_Load(object sender, EventArgs e)
      {
          var node = SiteNavigation.SelectedNode;
          var pageID = node.Value;
            
          // call CmsManager.GetPage, check the page type and disable the link if the page is group or not
      }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    12 Apr 2010
    Link to this post
    Ivan,

    I have created my own Duplicate Page Group control in C#. I have included the code and instructions:

    Under /Sitefinity/UserControls/ folder, create a new folder called "DuplicatePageGroup". Under /Sitefinity/UserControls/DuplicatePageGroup/ create a new UserControl called "DuplicatePageGroupControl.ascx". Include the code behind for this UserControl.

    The ASCX:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="DuplicatePageGroupControl.ascx.cs" Inherits="Sitefinity_UserControls_DuplicatePageGroup_DuplicatePageGroupControl" %>
     
    <asp:LinkButton ID="LinkButton6" Text="Duplicate page group" ToolTip="Duplicate this page group" runat="server" OnPreRender="LinkButton6_PreRender" OnClick="LinkButton6_Click"></asp:LinkButton>

    The ASCX.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms;
    using Telerik.Cms.Data;
    using Telerik.Cms.Web.UI;
     
    public partial class Sitefinity_UserControls_DuplicatePageGroup_DuplicatePageGroupControl : System.Web.UI.UserControl
    {
        Guid PageID = Guid.Empty;
     
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        protected void LinkButton6_PreRender(object a, EventArgs e)
        {
            this.LinkButton6.Enabled = false;
            if (IsPageGroup())
            {
                this.LinkButton6.Enabled = true;
            }          
        }
     
        protected void LinkButton6_Click(object sender, EventArgs e)
        {
            if (IsPageGroup())
            {
                var _CmsManager = new CmsManager();
                var _ICmsPage = (ICmsPage)_CmsManager.GetPage(PageID);
                string CopyName = GetCopyName(_ICmsPage, 1);
                var CopyOf = _CmsManager.DuplicatePage(_ICmsPage, CopyName, true);
                _CmsManager.SavePage(CopyOf);
     
                Response.Redirect("~/sitefinity/admin/Pages.aspx");
            }
        }
     
        private bool IsPageGroup()
        {
            SiteMapPanel _SiteMapPanel = (SiteMapPanel)this.Parent.Parent.Parent;
            Guid _SelectedPageID = _SiteMapPanel.SelectedPageID;
            var _CmsManager = new CmsManager();
            Telerik.Cms.IPage _IPage = _CmsManager.GetPage(_SelectedPageID);
            if (_IPage != null)
            {
                if (_IPage is CmsPage)
                {
                    if ((_IPage as CmsPage).PageType == CmsPageType.Group)
                    {
                        PageID = _IPage.ID;
                        return true;
                    }
                }
            }
     
            return false;
        }
     
        private string GetCopyName(Telerik.Cms.ICmsPage _ICmsPage, int Count)
        {
            string CopyName = _ICmsPage.MenuName + "_Copy" + Count;
     
            var _CmsManager = new CmsManager();
            foreach (ICmsPage _CmsManagerPage in _CmsManager.GetPages())
            {
                if (_CmsManagerPage.MenuName == CopyName)
                    return GetCopyName(_ICmsPage, Count + 1);
            }       
     
            return CopyName;
        }
    }

    Under /Sitefinity/Admin/ControlTemplates/Pages/ add the following to the SiteMapPanel.ascx UserControl:

    <%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
    <%@ Register Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register Src="~/Sitefinity/UserControls/DuplicatePageGroup/DuplicatePageGroupControl.ascx" TagName="DuplicatePageGroupControl" TagPrefix="cc" %>
     
    <asp:LinkButton ID="createBtn" CommandName="New" CssClass="CmsButLeft new" runat="server">
        <strong class="CmsButRight light"><asp:Literal runat="server" Text="<%$Resources:CreateAPage %>"></asp:Literal></strong>
    </asp:LinkButton>
    <h2 id="sitemap"><asp:Literal runat="server" Text="<%$Resources:SiteMap %>"></asp:Literal></h2>
    <div class="sitemapTree">
    <telerik:RadTreeView ID="SiteNavigation" EnableEmbeddedSkins="false" Skin="SitefinitySiteMap"  EnableDragAndDropBetweenNodes="true" runat="server" Width="190"></telerik:RadTreeView></div>
    <div id="mess"><!-- -->
    <sfWeb:MessageControl runat="server" ID="message">
        <ItemTemplate>
            <asp:Literal runat="server" ID="messageText"></asp:Literal>
        </ItemTemplate>
    </sfWeb:MessageControl>
    </div>
    <div id="smWrapper" style="display:none;">
    <div class="SiteMapTools">
    <h3><asp:Literal runat="server" Text="<%$Resources:SelectAPageAboveAnd %>"></asp:Literal>:</h3>
        <ul>
            <li class="PageDefault">
                <asp:LinkButton ID="LinkButton1" CommandName="HomePage" Text="<%$Resources:SetHomePage %>" ToolTip="<%$Resources:SetHomePageTooltip %>" runat="server"><asp:Literal runat="server" Text="<%$Resources:SetAsHomePage %>"></asp:Literal></asp:LinkButton>
            </li>
            <li class="PageDuplicate">
                <asp:LinkButton ID="LinkButton5" CommandName="Duplicate" Text="<%$Resources:DuplicatePage %>" ToolTip="<%$Resources:DuplicatePageToolTip %>" runat="server"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:DuplicatePage %>"></asp:Literal></asp:LinkButton>
            </li>
            <li class="PageDuplicate">
                <cc:DuplicatePageGroupControl ID="DuplicatePageGroupControl" runat="server" />
            </li>
            <li class="PageUp">
                <asp:LinkButton ID="LinkButton2" CommandName="MoveUp" Text="<%$Resources:MovePageUp %>" ToolTip="<%$Resources:MovePageUpTooltip %>" runat="server"></asp:LinkButton>
            </li>
            <li class="PageDown">
                <asp:LinkButton ID="LinkButton3" CommandName="MoveDown" Text="<%$Resources:MovePageDown %>" ToolTip="<%$Resources:MovePageDownTooltip %>" runat="server"></asp:LinkButton>
            </li>
            <li class="PageDelete">
                <asp:LinkButton ID="LinkButton4" CommandName="Delete" Text="<%$Resources:Delete %>" ToolTip="<%$Resources:DeleteTooltip %>" runat="server"></asp:LinkButton>
            </li>
        </ul>
    </div>
    </div>


    Thanks
  4. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    01 Jun 2010
    Link to this post
    Thank you mcpdinkansas for your code to dulicate page groups. It workd great.  I need to duplicate a large section of our site and I can do it easily using the duplicate page group button. I just need to make the first page a page group page, duplicate it thus duplicating all pages underneath, then make the page group page a 'regular' page and recreate the content. But it saves A LOT of time without having to duplicate each and every page!


  5. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    21 Jun 2010
    Link to this post
    Hello, I've just read this thread.

    I have a page with some pages underneath that (no page groups), and that whole group of pages needs to be duplicated 35 times! I would expect that if I chose the higher level page and clicked 'duplicate page', that page and any pages underneath it are copied. But that isn't the case.

    Hi can someone tell me if what is described in this thread is the ONLY way to duplicate entire sections of a site?

    Thanks, Louise.

  6. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    21 Jun 2010
    Link to this post
    Hey Louise,

    You are correct, you need custom control/code to duplicate pages underneath another page/page group. My code will work for your situation, you will just need to remove the IsPageGroup() check withinLinkButton6_Click   method.

  7. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    29 Jun 2010
    Link to this post
    Hello, thank you for your response, I'm going to try it out now as it has become a very urgent requirement!

    thanks a lot
  8. sweety
    sweety avatar
    28 posts
    Registered:
    28 Jun 2010
    05 Aug 2010
    Link to this post
    hello

    I have used page group in my site, is there any way to show all the pages of that group in sitemap, As sitetree view not show the pages that lie in a group.

    please help me out...

  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Aug 2010
    Link to this post
    Hello sweety,

    I have attached a small video showing that page groups show their children pages. Check if your page group is set not to show in navigation, or if any other pages have this property set.

    On another note - lets try to keep our forum threads on topic. The question you are asking does not relate to the topic of this forum thread.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    23 Aug 2010
    Link to this post
    I find that the Menu Label becomes the Page Name after duplicating... how can i make the Menu Label stay the same? Or at the very least become the Title?

    Thank you.
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Aug 2010
    Link to this post
    Hi Laura,

    When you duplicate a page the text of menu item is populated from of the page. The Page name is different and by default we append _copy to the name of duplicated page. The menu label is not altered. You cannot have the same page name for two or more nodes.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    31 Aug 2010
    Link to this post

    I think it may  be the version i am using for this site... Sitefinity 3.6

    It is taking the page name and placing it into the menu name.

     

    So before:
    Page name:  group_page.aspx
    Menu Name: Group Page
    Title: Group Page

    After:
    Page name:  group_page.aspx
    Menu Name: group_page
    Title: Group Page

  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    31 Aug 2010
    Link to this post
    Hello Laura,

    We are not able to reproduce the problem with 3.7 SP3 edition. You could try upgrading your project or  experimenting locally with a blank project.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    01 Nov 2010
    Link to this post
    Sorry to bring this back up however we ave upgraded to 3.7 SP2.  I created two test pages. One Page Group and one child page. After I do the duplicate page group, the page group PARENT page DOES behave the way you decribed below however for its CHILD - the page name becomes the text in the Menu Label box. I have attached two screenshots. If there is a quick fix in the code it would save me A LOT of time.  I appreciate any suggestions. My code is exactly like it is in this thread.
    Thank you!!
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Nov 2010
    Link to this post
    Hello Laura,

    I am sending you a short video from demo.sitefinity.com which is running Sitefinity 3.7 SP4.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    01 Nov 2010
    Link to this post
    thank you VERY much for the video - Yes duplicate page works as you showed however it 's the duplicate page group that puts the page name into the menu label.
  17. stuthom
    stuthom avatar
    1 posts
    Registered:
    19 Nov 2008
    28 Jan 2011
    Link to this post
    This is outstanding guys - thanks very much for the solution!  Exactly what we've been looking for today.
  18. Ivor
    Ivor avatar
    20 posts
    Registered:
    28 Sep 2010
    09 Feb 2011
    Link to this post
    Genius Mcpdinkansas! You saved me a lot of time.

    Why on earth didn't Telerik include this in the first place?



  19. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    09 Feb 2011
    Link to this post
    As a software developer myself I can understand that getting every little functional aspect of something 100% is not possible. I think as a community it's our job to help out with this and provide each other with solutions.

    Telerik provides amazing support and has always been able to help me through figuring out any issues I've had with their products.

    Thanks for the feedback.
  20. Ivor
    Ivor avatar
    20 posts
    Registered:
    28 Sep 2010
    10 Feb 2011
    Link to this post
    Ah well, this fixes the icon alignment problem it creates....

    Save the attached to: \Sitefinity\Admin\Themes\Default\Images
  21. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    10 Feb 2011
    Link to this post
    Awesome addition! I completely forgot I had to update that graphic.
Register for webinar
21 posts, 0 answered