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

Forums / Developing with Sitefinity / Does Page.DateCreated Ever Get Set?

Does Page.DateCreated Ever Get Set?

4 posts, 1 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    11 Dec 2009
    Link to this post
    Hello,

    I'm creating CmsPages programmatically and DateCreated is always DateTime.MinValue (1/1/0001). The DateCreated property is read-only so I can set it myself.

    Is there some action I have to take before Sitefinity decides to set this property?

    I create the page, check it out, save it and publish it. At no point is DateCreated ever set.

    Here's the code:
                    ICmsPage CmsPage = Manager.CreatePage("Sample"); 
     
                    CmsPage.MasterPage = "Article.master"
     
                    CmsPage.Title = "Sample Title"
                    CmsPage.Description = "Sample Description"
     
                    // Read-only. This is of no help. 
                    //CmsPage.DateCreated = DateTime.Now; 
     
                    IStagedPage staged = CmsPage.Staged.CheckOut(); 
                    Guid templateId = ((IPageTemplate)Manager.GetTemplates()[0]).ID; 
                    staged.SetTemplate(templateId, "Dummy"); 
     
                    staged.AddControl("Content"
                            new LiteralControl("<p>Sample content.</p>")); 
                     
                    Manager.SavePage(CmsPage); 
                    CmsPage.Publish();
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Dec 2009
    Link to this post
    Hello Jeff,

     Try using IPage object. The DateCreated will be set as DateTime.Now.

    var cmsManager = new CmsManager();
    IPage newPage = cmsManager.CreatePage("NEWPAGE");
    cmsManager .SavePage(newPage);


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    14 Dec 2009
    Link to this post
    Thanks Ivan. That did the trick.

    It's worth noting that IPage doesn't have fields like Description and Title.

    To get back to a ICmsPage, I created and saved the page as you demonstrated. Then I did a cmsManager.GetPage and casted the result to an ICmsPage.

    Thanks again for your help.

    Jeff
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Dec 2009
    Link to this post
    Hi Jeff,

     Always glad to help to the community.


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 1 answered