Thursday, June 25, 2015

Top Visitors Web Part

Hi,

There was a requirement for our customers i.e. to display the top visitors on every page.
For this our design plan was
1)To log the user details like userid, user display name, site url and logged time.
2)Stored procedure to insert the values into the table
3)Stored procedure the read the values from the table.

Before starting we have created the table with column names as below
For the LoggedinDate column we have set the DataType as below
Because, as soon as values get inserted in the row it would take the system under LoggedinDate column
Post this created a stored procedure to insert values into the table
Post this ,created a stored procedure to get the users as below


On Page load event, got the userid, user displayname, siteID, site url through SPWeb.
Post this, was able to insert the values into the DB through stored procedure
Now through another stored procedure, was able to get the Top Visitors to display through Grid View as below
Finally was able to display the Top Visitors list as below