Registered Users

Registered Users

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Diagnostics.Log
  • Sitecore.Security.Accounts.User
  • Sitecore.Security.Accounts.UserManager
  • Sitecore.Security.Domains.Domain
  • Sitecore.Security.UserProfile
  • Sitecore.StringUtil
  • System.Exception

Registered Users C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

var userList = Sitecore.Security.Accounts.UserManager.GetUsers();
if (userList == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag(); //Div

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string itemName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", itemName);
output.RenderEndTag(); //P

foreach (Sitecore.Security.Accounts.User user in userList)
{
    Sitecore.Security.Domains.Domain domain = user.Domain;
    if (domain != null && domain.Name == "demo")
    {
        Sitecore.Security.UserProfile profile = user.Profile;
        try
        {
if (profile != null)
{
    if (profile.UserName != "demo\\Anonymous")
    {
        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
        output.Write(profile.UserName + " ");
        output.Write(profile["First Name"] + " ");
        output.Write(profile.GetCustomProperty("Last Name") + " ");
        output.Write(profile.FullName + " ");
        output.Write(profile.Email + "<br/>");
        output.Write(profile.LastUpdatedDate.ToString() + "&nbsp;");
        output.Write(profile.LastActivityDate.ToLongDateString() + "&nbsp;");
        output.Write(profile.LastActivityDate.ToLongTimeString() + "<br/><br/>");
        output.RenderEndTag(); //Div
    }
}
        }
        catch (System.Exception ex)
        {
Sitecore.Diagnostics.Log.Error("exception", ex);
output.RenderEndTag(); //Div
continue;
        }
        
    }
    
}
output.RenderEndTag(); //Div


Registered Users C# Web Control Output

demo\DemoUser1   Demo User One demouser1@theinsidecorner.com
12/8/2012 6:54:55 AM Tuesday, October 07, 2014 6:44:30 AM

demo\DemoUser2   Demo User Two demouser2@theinsidecorner.com
12/8/2012 6:55:37 AM Tuesday, October 07, 2014 6:44:30 AM

demo\DemoUser3   Demo User Three demouser3@theinsidecorner.com
12/8/2012 6:56:30 AM Tuesday, October 07, 2014 6:44:30 AM