Skip to main content

Page Hit Counter in SharePoint

You would have seen many sites displaying page hit counters. To display this in SharePoint page, insert the “Hit Counter” web component from SharePoint Designer.Open your site or your sites Master page to insert this component. For the demonstration purpose, I’ve use my default.aspx to insert the “Hit Counter” component. Once the page is opened in SharePoint Designer, place the cursor where you want to insert the hit counter. Go to Insert --> Web Component.



Click on the Web Component, this will display the available web components. You can find different types of other components readily available.



Click on the Hit Counter component, this will display different counter styles. Select any one style from the list. I have selected the below marked style.


Click on “Finish”, this will open the below Hit Counter Properties window.

You can even create your own Hit Counter. Use “Reset counter to” to reset the counter from a given number. To display fixed number of digits use “Fixed number of digits” property. Click on “Ok”, the hit counter will be inserted to your page. The below code will be inserted in your page to display the counter.



Now, preview your page from SharePoint Designer / a Web browser. You can see the Hit Counter incremented for each hit.

Comments

Popular posts from this blog

How to get SPUser or SPGroup from Person or Group field

You have person or group field in SharePoint list and you want to programmatically get the user or person. The below code to gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field: //get SPUser SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString()); SPUser user = userFieldValue.User; This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed: //Multiple choices are allowed SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString()); foreach (SPFieldUserValue userFieldValue in userFieldValueCollection) {     Console.WriteLine("     " + userFieldValue.User.LoginName); } And when group

SharePoint publishing page scheduling

In SharePoint 2010 publishing enabled team site collection is not showing schedule button in publish ribbon. Solution: Here is how to enable it  though the UI: Locate the SharePoint Server Web site on which you want to enable content approval and item scheduling. Click  Site Actions , click  Site Settings , and then click  Modify Pages Library Settings . Under  General Settings , click  Versioning Settings . Click  Yes  next to  Content Approval , and then click  OK . Click  Manage item scheduling .   Click to enable the  Enable scheduling of items in this list  check box, and then click  OK .

Changing Content Type Hub URL

Change the Hub URL through powershell by using: Set-SPMetadataServiceApplication -Identity " " -HubURI " " For Ex: Set-SPMetadataServiceApplication -Identity "Managed Metadata Service" -HubURI "http://contenttype.Domain.Com" When you try to do this you get this rather scary message: This is SharePoint telling you that this is a major thing so be careful! Essentially all your content types that you have published out will be removed if they can, and you have to republish all of your content types out again which can cause some issue.