Wednesday, February 17, 2010

Get Sitecore User creation date

Sitecore User creation date value isnt available readily from Sitecore User object. However, I know it is possible to get the creation date, since in "Edit User" XAML in Sitecore has this field populated.

To find out how Sitecore get the creation date, I have dissected Sitecore.Client.dll. In this dll, I believe (correct me if i am wrong) most if not all of the code behind for Sitecore Application reside in this dll. After tracing through the "Edit User" xml, I found out that the Sitecore.Shell.Applications.Security.EditUser is the code behind for the xml that I am after.

Below is the code to get User creation date.

MembershipUser user2 = Membership.GetUser(user.Name);
if (user2 != null)
{
CultureInfo culture = User.Current.Profile.Culture;
this.LastLoginDate.Text = DateUtil.FormatLongDateTime(user2.LastLoginDate, culture);
this.CreationDate.Text = DateUtil.FormatLongDateTime(user2.CreationDate, culture);

this.LastActivityDate.Text = DateUtil.FormatLongDateTime(user2.LastActivityDate, culture);

this.LastPasswordChangedDate.Text = DateUtil.FormatLongDateTime(user2.LastPasswordChangedDate, culture);
this.LastLockoutDate.Text = FormatDate(user2.LastLockoutDate, culture);
}

No comments:

Post a Comment