Wednesday, June 15, 2011

How to check which users have logged in SharePoint?

If you need to ever find out, which authenticated users have logged into your site, you need to visit this page. You have to be the Site Collection admin to see this list.

http://SERVER/_catalogs/users/simple.aspx

This will provide you the information about the user when was the 1st time the user ever logged into the site. This list is a hidden list. This list by default has 33 columns describing the user and the extended version of this list has 64 columns.

If you ever have a need to check when a user has logged in last time, you could simply add a small web part to the home page of your site. The main function of the web part is to update the list. When you update a row of data, it automatically puts the time stamp of the last modified date.

Here is some sample code:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite oSiteCollection = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oWeb = oSiteCollection.RootWeb)
{
oWeb.AllowUnsafeUpdates = true;
SPList myUserList = oWeb.SiteUserInfoList;
SPListItem myUserItem = myUserList.Items.GetItemById(myLoggedInUser.ID);
myUserItem.Update();
}
}
}
catch (Exception e1)
{
Your Error Handling
}
});

1 comment:

  1. Hi Kartik,
    use which web part and where to insert this code??
    (using Sp2013 online( Office 365))
    thanks,
    Stefan

    ReplyDelete