Click here to Skip to main content
Licence CPOL
First Posted 3 Feb 2009
Views 17,427
Bookmarked 18 times

How to: Create a footer for your SharePoint pages

By Jakob Flygare | 3 Feb 2009
This article shows how to create a footer for your SharePoint pages.
   4.50 (4 votes)

1

2
1 vote, 25.0%
3

4
3 votes, 75.0%
5
4.50/5 - 4 votes
μ 4.50, σa 2.02 [?]
 

Introduction

If you want to use your SharePoint like a CMS, you probably would like to have a text at the bottom of your pages stating when it was last modified and by whom.

Background

The topic and code of this article was first presented here: http://itfootprint.wordpress.com/2007/10/18/sharepoint-footer-custom-control-last-modified-date/.

It was modified with the addition of multi-language support (using out-of-the-box resources from SharePoint) and some SharePoint styling here: http://www.the-north.com/sharepoint/post/Building-a-multi-lingual-Last-Modifed-Footer-for-MOSS.aspx.

This code goes a step further and enables support of local time zones as the controls presented by the postings above only present time in GMT.

This is done by using the UTCToLacalTime method of the SPTimeZone class, that can be accessed through the RegionalSettings property of the current site.

The addition of multilingual labels has been dropped in this user control, but can be added using the technique presented in the posting in the second link above.

Using the Code

In order to use the code, you need to place the user control in your 12 hive at this location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12.

The code for your user control:

<%@ Control Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.Administration" %>
<script runat="server">
    string stLastModifiedDate = string.Empty;
    string stLastModifiedBy = string.Empty;
    string stLastModifiedByMemberID = string.Empty;    
    
    string stTxt = string.Empty;
    public string FileName()
    {
        return System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
    }
    void Page_Load(object sender, EventArgs e)
    {
        string stPageName = FileName();
        using (SPSite RootSite = new SPSite(Page.Request.Url.ToString()))
        {
            using (SPWeb SiteCollection = RootSite.OpenWeb())
            {
                string stPath = RootSite.MakeFullUrl(stPageName);
                SPFile File = SiteCollection.GetFile(stPath);
                DateTime dateLastModifiedDate = File.TimeLastModified;
                stLastModifiedDate = 
                  SiteCollection.RegionalSettings.TimeZone.UTCToLocalTime(
                  dateLastModifiedDate).ToString();
                
                SPUser ModifierUser = File.ModifiedBy;
                stLastModifiedBy = ModifierUser.Name.ToString();
                stLastModifiedByMemberID = ModifierUser.ID.ToString();
                stTxt = "Last modified by:<a onclick=\"GoToLink(this);" + 
                  "return false;\" href=\"../_layouts/userdisp." + 
                 "aspx?ID=" + stLastModifiedByMemberID + 
                 "\">" + stLastModifiedBy + 
                 "</a>  " + stLastModifiedDate;
            }
        }
    }
</script>
<table class="pageFooter">
    <tr>
        <td>
            <%= stTxt %>
        </td>
    </tr>
</table>

The CSS: I have added the pageFooter CSS class in the pageContent.css stylesheet:

.pageFooter
{   font-family:Arial;
    font-size:10px;
    color:#4d4d4d;
    line-height: 12px;

}

.pageFooter A:link
{ 
    color:#8b9700;
}

Finally, you place your control on your page layouts like this:

Register your control:

<%@ Register TagPrefix="Flygare" 
    TagName="PageFooter" src="~/_controltemplates/PageFooter.ascx" %>

Insert your control:

<Flygare:PageFooter id="PageFoot" runat="server" enableviewstate="true">
</Flygare:PageFooter>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jakob Flygare

Web Developer

Denmark Denmark

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood Share Pinmemberjasonp1210:12 7 Jan '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120222.1 | Last Updated 3 Feb 2009
Article Copyright 2009 by Jakob Flygare
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid