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

Forums / Developing with Sitefinity / How to set the DateCreated field of a IPage

How to set the DateCreated field of a IPage

6 posts, 0 answered
  1. Doug
    Doug avatar
    34 posts
    Registered:
    20 Apr 2010
    11 Jun 2010
    Link to this post
    Hello,
    I am creating a series of pages pragmatically and all is going well there except for the DateCreated field.  When I create a page I have a custom control that lists out all of the pages that are created by way of this process and it is displaying the created date of these pages as 01/01/0001 (null).  And sure enough if I look in the sf_PageContentBase table the DateCreated column for this page is null. 

    IPage only exposes a public getter for the DateCreated, how do I set this value?  Relevant code:

    CmsManager mgr = new CmsManager();
     
    ICmsPage page = mgr.CreatePage(RemoveWhiteSpaceFromString(this.labelTitle.Text), new Guid(Convert.ToString(ConfigurationManager.AppSettings["ArchiveShowParentPageGuid"])));
    IPageTemplate template = mgr.GetTemplate("ShowMaster");
    page.Staged.CheckOut();
     
    page.AddUrl(CreatePageURL());
    page.DefaultUrlIndex = 0;
     
    page.MenuName = CreateMenuLabel();
    page.Staged.SetTemplate(template.ID, "Master");
     
    AddControlsToPage(mgr, page);
    page = (ICmsPage)mgr.GetPage(page.ID, true);
    page.Staged.CheckIn();
    page.Publish();

    The AddControlsToPage method looks similar to this:

    Page = (ICmsPage)Manager.GetPage(Page.ID, true);
    Page.Staged.AddControl("News", "NewsControl", BuildArchiveNewsView());

    Thanks.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Jun 2010
    Link to this post
    Hello Doug,

    Thank you for using our services.

    Could you please call mgr.SavePage(page) right after you have created it?
    CmsManager mgr = new CmsManager();
      
    ICmsPage page = mgr.CreatePage(RemoveWhiteSpaceFromString(this.labelTitle.Text), new Guid(Convert.ToString(ConfigurationManager.AppSettings["ArchiveShowParentPageGuid"])));
    mgr.SavePage(page);
    page = (ICmsPage)mgr.GetPage(page.ID);
    IPageTemplate template = mgr.GetTemplate("ShowMaster");
    page.Staged.CheckOut();


    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.
  3. Doug
    Doug avatar
    34 posts
    Registered:
    20 Apr 2010
    17 Jun 2010
    Link to this post
    Hi Radoslav,
       I did as you said but, unfortunately, I am now getting an exception when I call page.Staged.CheckOut() with the exception: IOdbClass must be joined to a transaction.

    Thanks for any help you might be able to provide. 

    mgr.SavePage(page);
    page = (ICmsPage)mgr.GetPage(page.ID);
     
    IPageTemplate template = mgr.GetTemplate("ShowMaster");
    page.Staged.CheckOut();
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    18 Jun 2010
    Link to this post
    Hello Doug,

    After you save the page can you get the staged instance and work on it:
    IStagedPage staged = page.Staged.CheckOut();


    Best wishes,
    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
  5. Doug
    Doug avatar
    34 posts
    Registered:
    20 Apr 2010
    22 Jun 2010
    Link to this post
    Hi Radoslav,
        I corrected the IOdb error, however, I am still having the same problem of the DateCreated field going into the PageContentBase table as Null. Any thoughts?
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    23 Jun 2010
    Link to this post
    Hello Doug,

    Please take a look at the attached create sample page web form. It returns the correct date.

    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
Register for webinar
6 posts, 0 answered