How to get created date of a user in sitecore. I am creating a script in c# to list out all sitecore users and its profile fields such as Last active date, Last Updated Date etc. I have got all users in a list using -
var users = Sitecore.Security.Accounts.UserManager.GetUsers();
foreach (Sitecore.Security.Accounts.User user in users)
{
ltLastActiveDate = user.Profile.LastActivityDate;
ltCreatedDate = user.Profile // ? No idea
}
I have no idea how to get created date for user.
Try it:
var users = Sitecore.Security.Accounts.UserManager.GetUsers();
foreach (Sitecore.Security.Accounts.User user in users)
{
var membershipUser = System.Web.Security.Membership.GetUser(user.Name, false);
if (membershipUser != null)
{
var date = membershipUser.CreationDate;
}
}
cheers.
The Sitecore user properties are really just complimentary to the standard .NET membership provider that already takes care of a lot of stuff like this. As such you should convert the Sitecore user (Sitecore.Security.Accounts.User) to a .NET user (System.Web.Security.MembershipUser) in order to find the creation date.
Here is an example:
System.Web.Security.MembershipUser membershipUser = System.Web.Security.Membership.GetUser(user.Name);
if (membershipUser != null)
{
DateTime creationDate = membershipUser.CreationDate;
}