How to get the Modified By and Last Modified Date in the MOSS 2007 Publishing Portal?

In the intranet publishing portal, many times it is wonderful to show the last modified by and last modified date in multi-authoring environment to display the last modified information.

In MOSS 2007 environment, it is ideally done using the custom control or user control hosted in the MasterPage as footer region. Use following code to extract the last modified by and last modified date for the given page in the publishing portal.

using Microsoft.SharePoint;

String PageName = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
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.Name.ToString();

lblModifiedBy.Text = ModifiedBy;
lblModifiedDate.Text = LastModifiedDate;

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s