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

Forums / Developing with Sitefinity / Show Last Modified Date on each page

Show Last Modified Date on each page

7 posts, 0 answered
  1. Dragomir Enachi
    Dragomir Enachi avatar
    7 posts
    Registered:
    12 Nov 2009
    01 Sep 2010
    Link to this post
    Hello,

    how can I display last modified date on each page?  I have created custom user control but I can't get the date there. Please help me.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Sep 2010
    Link to this post
    Hi Dragomir Enachi,

    I am not sure the data for which modified object you want to show "Show Last Modified Date on each page"
    If I assume that you want to get the last modified data of the current page you can use the code below


    var cmsManager = new CmsManager();
     var node = SiteMap.CurrentNode as CmsSiteMapNode;
     if (node != null)
     {
         var currentPage = (ICmsPage)cmsManager.GetPage(node.PageID);
         if (currentPage != null)
         {
             var modified = currentPage.DateModified.ToShortDateString();
             Response.Write(modified);
         }
     
     }


    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. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    01 Sep 2010
    Link to this post
    Hi Dragomir Enachi

    Here is  sample code for you

    var manager = new CmsManager();
    var currentPage = (ICmsUrlContext)this.Context.Items[UrlHelper.CmsPageKey];
    var Id = new Guid(currentPage.PageID.ToString());
     
    var objPage = manager.GetPage(Id);
     
    var modifiedDate = objPage.DateModified;

    Best,

    George
  4. Dragomir Enachi
    Dragomir Enachi avatar
    7 posts
    Registered:
    12 Nov 2009
    01 Sep 2010
    Link to this post
    Sorry, where should I put the code?
    I tried in inner.master and in custom user control.. not working :(
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Sep 2010
    Link to this post
    Hello Dragomir Enachi,

    On the page for which you want to get the modified data. Create a user or custom control and add this code inside Page_Load or PreRender

    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
  6. Dragomir Enachi
    Dragomir Enachi avatar
    7 posts
    Registered:
    12 Nov 2009
    01 Sep 2010
    Link to this post

    I've created a custom control called showdate(cs&ascx files),

    ASCX contains
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="showdate.ascx.cs" Inherits="showdate" %>
    <div class="GeneralEnquiryForm">
    <asp:Label ID="Label1" runat="server"></asp:Label>        
    </div>

    and CS contains

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.ComponentModel;

    using Telerik.Web.UI;
    using Telerik.Cms;
    using Telerik.Cms.Web;

    protected void Page_Load(object sender, EventArgs e){
    var cmsManager = new CmsManager();
     var node = SiteMap.CurrentNode as CmsSiteMapNode;
     if (node != null)
     {
         var currentPage = (ICmsPage)cmsManager.GetPage(node.PageID);
         if (currentPage != null)
         {
             var modified = currentPage.DateModified.ToShortDateString();
             Label1.Text = modified;
         }
     
     }
    }

    I tried to add the Showdate control to Inner template and I get an error :-|
    I did it right or maybe I did anything wrong?

    here's the error:

     

    Sitefinity\UserControls\showdate\showdate.cs(17): error CS1518: Expected class, delegate, enum, interface, or struct; line 17 has:

    protected void Page_Load(object sender, EventArgs e)

     

  7. Dragomir Enachi
    Dragomir Enachi avatar
    7 posts
    Registered:
    12 Nov 2009
    01 Sep 2010
    Link to this post
    Solved,
    The CS code should be

    public partial class showdate : UserControl {
    protected void Page_Load(object sender, EventArgs e){

     var cmsManager = new CmsManager();
     var node = SiteMap.CurrentNode as CmsSiteMapNode;
     if (node != null)
     {
         var currentPage = (ICmsPage)cmsManager.GetPage(node.PageID);
         if (currentPage != null)
         {
             var modified = currentPage.DateModified.ToShortDateString();
             Label1.Text = modified;
         }
     
     }
    }
    }


    Thanks for helping.

Register for webinar
7 posts, 0 answered