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

Forums / General Discussions / using CopyPageData

using CopyPageData

4 posts, 1 answered
  1. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    01 Dec 2010
    Link to this post
    • I am trying to copy a page programatically.  When the CopyPageData() method executes I get the following error:

    Not a managed persistent instance.

    Parameter name: component

    Actual value was Telerik.Sitefinity.Pages.Model.PageNode.

     

    • Here is my code, which is commented to explain exactly where the problem is:

    var fluent = App.WorkWith().Page();

    var mgrFluent = fluent.PageManager;

    PageData sourcePageData =

    mgrFluent.GetPageDataList().Where(pd => pd.Title == "myExistingPageDataTitle").FirstOrDefault();

    // my MakeNewPage() creates a page that can display in the SF gui (a valid one)

    // and is in a row of both sf_page_data and sf_page_node

    PageData pd1 = MakeNewPage("theNewPageTitle4");

     

    var ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true);

    // in debug both sourcePageData and pd1 are populated w id etc from db

    mgrFluent.CopyPageData(sourcePageData, pd1);

    //  same error if I use this overload

    // mgrFluent.CopyPageData(sourcePageData, pd1, ci, ci, true);

    How can I successfully use CopyPageData() ?  Thanks.

  2. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    03 Dec 2010
    Link to this post
    Any progress on this?  Solving this is becoming critical on our Gantt chart.  :-)

    Thanks.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Dec 2010
    Link to this post
    Hello Phil,

    You have to operate with the page node instead of using the PageData object.

    var facade = App.WorkWith()
                .Page(new Guid(pageId))
                .Duplicate();
                 facade.SaveChanges();
     
    var node = facade.Get();
    SiteMapBase.Cache.Flush();

    You can get the page by another property using the LINQ expression and use a DO to set the properties on the duplicated page.

    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
    Answered
  4. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    07 Dec 2010
    Link to this post
    That worked.  On my first try I got the error: Object references between two different object scopes are not allowed ....   So I had to create the parent PageNode object and do the Duplicate method w the same App.WorkWith.Page object.

    var mgr = App.WorkWith().Page(guidSourcePage);

    PageNode parentPage =

    mgr.PageManager.GetPageNodes().Where(pi => pi.Id == parentId).FirstOrDefault();

     

            mgr.Duplicate().Do(

                    p =>

                    {

                        p.Title = newPageName;

                        p.UrlName = newPageName;

                        p.ShowInNavigation = true;

                        p.Parent = parentPage; 

                        if (p.Page != null)

                        {

                            p.Page.Title = newPageName;

                        }

                    }).SaveChanges();

4 posts, 1 answered