I recently came across a client requirement to have a custom built footer with last modified details in its MOSS Intranet Portal. I found that following code returns a date in future, which is very strange.
<PublishingWebControls:LastModifiedIndicator runat="server" />
Hence I resolved to the build a custom footer control which returns the last modified date and other modified details.
Ok Show me the code.
<%@ Control Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.Administration" %>
<script runat="server">
string text = "";
public string FileName()
{
string FilePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
return FilePath;
}
void Page_Load(object sender, EventArgs e)
{
String PageName = FileName();
using(SPSite RootSite = new SPSite(Page.Request.Url.ToString()))
{
using (SPWeb SiteCollection = RootSite.OpenWeb())
{
string path = RootSite.MakeFullUrl(PageName);
SPFile file = SiteCollection.GetFile(path);
String LastModifiedDate = file.TimeLastModified.ToLongDateString();
String ModifiedBy = file.ModifiedBy.ToString();
text = "Page was Last Modified on "+LastModifiedDate+" by "+ModifiedBy;
}
}
}
</script>
<table border='0' width='100%'>
<tr>
<td align="right">
<small>
<%= text %>
</small>
</td>
</tr>
</table>
Once you finished coding your user control, follow the steps below to wack it on your SharePoint Site.
-
Save the ascx file in CONTROLTEMPALTES folder in your 12 hive.
-
Register the user control in your master page
<%@ Register TagPrefix="MyFooter" TagName="Footer" src="~/_controltemplates/MyCustomFooter.ascx" mce_src="~/_controltemplates/MyCustomFooter.ascx" %>
-
Add your control to the appropriate place on the master page. Which should be at the bottom of the page!
<MyFooter:Footer id="IdCustomFooter" runat="server" EnableViewState="true"> </MyFooter:Footer>
-
Save your master page (check in) and open your site. you should your footer with Last Modified Date and Modified details as shown in the image!
If you have any issues following the code above, please leave a comment. I will get back to you.


Posted by SharePoint, SharePoint and stuff : SharePoint Kaffeetasse 26 on October 22, 2007 at 1:06 pm
[...] SharePoint Footer Custom Control – Last Modified Date [...]
Posted by JC on November 2, 2007 at 4:46 am
Hi,
I have been doing some testing with the code above and am having issue getting it to work.
When i look at adding the register tagprefix line in my master page i recieve an error
Error Creating Control – PlaceHolder “MyFooter” is not a valid value for attribute ‘tagprefix’.
Great post by the way.. This is exactly the same requirement i have recently been asked for myself.
Cheers
JC
Posted by Whatever-ishere on November 21, 2007 at 4:59 pm
thanks for the GREAT post! Very useful…
Posted by Michelle on November 28, 2007 at 11:10 pm
Awesome post, thank you so much for this. Have been trying to get this working for ages with no luck till now:)
Posted by Jamie McAllister on February 15, 2008 at 2:34 pm
Nice work, really helped me out there. One comment though – to make it look like a built in Sharepoint component you might like to make the element look like this;
Posted by Jamie McAllister on February 15, 2008 at 2:36 pm
OK, let’s try that again. Make the table element in your code have class attribute set to “ms-informationbar”
Posted by Jamie McAllister on February 19, 2008 at 2:35 pm
Jag,
I’ve done a fairly major revision of your control. My new version provides multi-lingual text across Site Variations, and hyperlinks the Last Modified User Name to the User Information page.
Please check out my blog, and I trust you approve the update.
Jamie
http://www.the-north.com/sharepoint
Posted by Jag on February 20, 2008 at 1:19 am
Hi Jamie,
I appreciate your effort in getting back to me about the revision of my user control. This is what Social Networking tools like blogs are meant for.
I will review your code very soon and if possible I will post about it in this blog.
Ciao
Jag
Posted by Rina on May 18, 2008 at 11:25 am
I created a simple footer user control with a copyright, and followed your deployment instructions. I’m getting an error:
“This control cannot be displayed because it’s TagPrefix is not registered in this Web Form”.
Your help will be greately appreciated.
Posted by Jag on May 18, 2008 at 12:40 pm
Hey Rina,
you need to register your user control by adding
<%@ Register TagPrefix=”MyFooter” TagName=”Footer” src=”~/_controltemplates/MyCustomFooter.ascx” mce_src=”~/_controltemplates/MyCustomFooter.ascx
to your master top section.
All the best.
Jag
Posted by Rina on May 18, 2008 at 10:56 pm
Hi Jag,
Thanks for your response.
I registered the control in the master page trying every kind of TagPrefix I could come up with, to no avail.
I created an external ASP.Net application for the footer. Did you create a custom Definition application for the site and placed the user control there?
-Rina
Posted by KCR on May 31, 2008 at 7:42 am
Hi Jag
Did u try out the control in anonymous mode ?
KCR
Posted by JT on June 10, 2008 at 10:01 pm
I am having issues trying to run this in anonymous mode. Well, i am having issues getting sharepoint in to anon mode with this code running would be more precise.
Posted by Marcus on June 26, 2008 at 12:39 pm
Hi Guys
First thing, i too had problems in getting this control to work, but all it was due to, was when i was copying and pasting from your website it came out a RTF text rather than plain text.
This caused issues due to the ” ” (quotes) which had to be changed back to plain text within the web control code and also the registration and placement code.
Also since I was using the control within a layout page rather than within a materpage, the control had to be registered within that layout page not the masterpage.
I want to say thankyou for making this contol as this has helped me greatly in my work.
Posted by Saad Alam on July 14, 2008 at 4:45 pm
Hi,
I am using your code. I have a footer control in my web part pages. Now when the content in the web parts is updated it does not shows the correct modified date. It seems to me that it is always showing the created date.
Plz HELP!
Posted by rama on September 1, 2008 at 1:51 pm
i tried this i got an error
msc_src attribute is not allowed in this page can any one suggest me where i went wrong
Posted by Jag on September 3, 2008 at 9:52 am
In which page are you registering the user control. You should do it in site master page not in pagelayouts or web pages.
Posted by Rama on September 6, 2008 at 2:12 pm
i registered it in default.master but i dont understand the checkin concept do we need to edit in sharepoint designer checkout and checkin the master page i did an iisrest too its not working
Posted by Kunal on September 18, 2008 at 1:31 am
I tried using your code…its working fine on my SharePoint site home page…But it is not returning the correct values if I do any modifications in the web parts on that page…Do I need to add something extra in this code to achieve that??
I have Announcements, Tasks web parts on my page…and also it should chage the modified date if user adds any links in the top and left navigation…
Thanks in Advance..
Posted by Jason on October 3, 2008 at 6:29 am
I am getting this error:
Object reference not set to an instance of an object
for this line:
String ModifiedBy = file.ModifiedBy.ToString();
It appears that all user information is missing. Any idea why this might occur?
Thanks,
j
Posted by Jag on October 3, 2008 at 10:59 am
Hi Kunal,
Unfortunately, changes to the webparts are not governed by the webpage changes! Hence the footer control does not pick up the modifications.
It only picks up changes made to web content on the page.
Cheers
Jag
Posted by rhett on December 6, 2008 at 10:16 am
Huge THANK U!
Can you tell me how I can get name with presence or first lastname?
String ModifiedBy = file.ModifiedBy.ToString();
Posted by rhett on December 6, 2008 at 10:16 am
I guess I mean profile name.. not corp\myName
Posted by Florian on March 3, 2009 at 8:42 pm
Great Post! Very straight to the point. Thanks!!!
Posted by Amanda on April 19, 2009 at 6:32 pm
Urgent:
If I copied the exact code without changing anything , will it work? or do I need to edit some naming and definitions ? ?
Thankssssssss for the great post
Posted by SPPD080 SharePointPodcast - SharePointPodcast - SharePointCommunity on June 9, 2009 at 9:44 pm
[...] SharePoint Footer Custom Control – Last Modified Date [...]