Friday, June 5, 2009

Method to find SPFile last updated timestamp

//fetching web local regional setting
Thread.CurrentThread.CurrentCulture = SPContext.Current.Web.Locale;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite ElevatedSite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb(SPContext.Current.Web.ID))
{
SPFile ospFile = ElevatedWeb.GetFile(Page.Request.Url.ToString());
if (ospFile.Exists && DateTime.Compare(ospFile.TimeLastModified, ElevatedWeb.Created) > 0)
lastUpdated = ospFile.TimeLastModified.ToShortDateString();
else
lastUpdated = ElevatedWeb.Created.ToShortDateString();
}
}
});

1 comment:

  1. Thanks in support of sharing such a pleasant thought,
    article is pleasant, thats why i have read it completely

    Have a look at my weblog - diets That Work

    ReplyDelete