Click here to Skip to main content
11,410,750 members (63,424 online)
Click here to Skip to main content

How To: Create a Footer for your SharePoint Pages

, 15 May 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip shows how to create a footer for your SharePoint pages.

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 were first presented here.

It was modified with the addition of multi-language support (using out-of-the-box resources from SharePoint) and some SharePoint styling here.

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 site = new SPSite(Page.Request.Url.ToString()))
        {
            using (SPWeb web= site.OpenWeb())
            {
                string stPath = site.MakeFullUrl(stPageName);
                SPFile File = web.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)

Share

About the Author

Jakob Flygare
Web Developer
Denmark Denmark
No Biography provided

Comments and Discussions

 
Suggestionto insert a footer in master page [modified] Pinmembervanita khatnani1-Apr-13 20:29 
GeneralGood Share Pinmemberjasonp127-Jan-10 10:12 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 15 May 2012
Article Copyright 2009 by Jakob Flygare
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid