Click here to Skip to main content
14,301,387 members

How To: Create a Footer for your SharePoint Pages

Rate this:
4.50 (4 votes)
Please Sign up or sign in to vote.
4.50 (4 votes)
15 May 2012CPOL
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 Pin
vanita khatnani1-Apr-13 19:29
professionalvanita khatnani1-Apr-13 19:29 
GeneralGood Share Pin
jasonp127-Jan-10 9:12
memberjasonp127-Jan-10 9:12 

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

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

Article
Posted 3 Feb 2009

Tagged as

Stats

42.9K views
20 bookmarked