Friday, May 25, 2012

How to create host header Web Application in SharePoint 2010

When you create a web application in SharePoint 2010 you specify IIS web site name and a port number to which the web application will be running on, and to browse that web application you normally enter the server IP address and port number in the http url (e.g http://ServerIPAddress:portanumber) or you enter the machine name and port number. If you want to avoid entering IP Address or server machine name in the url and wanting to browse the web application by a domain host name e.g, there is an option called Host Address, while creating the SharePoint web application  you can specify the fully qualified host address which you will use for browsing the web application.

Below steps shows how you can specify the host address and configure it to route the request to your SharePoint web application.

Step1: First you need to decide the host name, let’s say your domain name is, and you want to create a web application with host address

Step2: Now you need to create a DNS entry on your AD server. Open the DNS from Start->Administrative Tools as shown in below screen shot

Step 3:  Explore your domain name and right click to create New Host (A or AAAA) entry.


Step 4:  Specify the new host name and IP address of your SharePoint WFE where your web application will be deployed

Step 5:  Once the DNS entry is done, you need to make Registry entry on your SharePoint WFE server. To make registry entry on the WFE server, just type regedit in Start->Run window

From the Registry Editor, explore HKEY_LOCAL_MACHIN -> System -> CurrentControlSet -> Control -> Lsa -> MSV1_0  as shown in below screen shot and edit the BackConnectionHostNames and specify fully qualified host name.

Once the registry entry is done, it is recommended to restart the server.

Step 6: Now you can create a web application in SharePoint 2010 from Central Administration and use the host header

Once the web application is created, you can create a root site collection. Now you can browse the web application by using the host header and specified port number (

Note: In your intranet if it still does'nt render the web application by browsing it by host adress, just make sure 1) you have entered the host address in your browser proxy 2) host address and IP address entry in host file on your local machine (Start->Run, type drivers and enter, click on etc folder you can see host file)

Thursday, May 24, 2012

How to track content changes of a publishing page in SharePoint 2010

Normally in SharePoint when you create a publishing page it goes through some approval cycle. During the approval cycle you check out the page and add/edit/remove some content and again check-in for further review. During this process reviewer would like to know what exactly is been modified in the content. Below steps shows how to track the changes between the versions of the page.

Problem Description:-
Let’s say you have created a publishing page and published it, again checkout it, modified, added some content, deleted some content and again published it. Now you want to see what has been changed between the versions.

Here are the steps to check the track changes:-

Step1: Click on View All Site Content from Site Actions menu display in top ribbon

Step 2: Click on the Pages link to open the pages library

Step3: Select the page which you have create and modified and want to see version changes. Below screen shot shows an example page title Testing versioning.

Step4: From the top ribbon click on Page option and then click on Page History as shown in below screen shot

Step5: Now you can see the track changes between latest version and the previous version in below screen shot.

As you can see the Versions in left section in the above screenshot, all versions will be automatically populated in drop down, you can select any version to compare and see track changes.

Tuesday, May 1, 2012

JavaScript error on page -_spbodyonloadfunctionnames is undefined

As you know in master and content page concept, the HTML ‘body’  is defined in master page and the content page defines only the html part that need to be rendered in the main placeholder in the master page. Now from a content page if you want to execute some JavaScript function on the body load event, the function needs to be invoked in body load event, to do that SharePoint defines an array in which all the JavaScript function which need to be called on body load can be added. When the body is loaded the onload event handlers executes each functions added in the _spBodyOnLoadFunctionNames array.

How it works:
SharePoint 2010 uses lots of JavaScript’s to make rich user experience, in run time it loads many JavaScript’s functions and add them in the spBodyOnLoadFunctionNames to execute it on body load event.

It uses init.js file to handle such JavaScript’s. SharePoint adds the reference to init.js file on run time within the head tag. This reference must be added before adding any function in spBodyOnLoadFunctionNames.

Below is the code which shows how the init file reference is added once page is rendered

document.write('<script type="text/javascript" src="/_layouts/1033/init.js?rev=BJDmyeIV5jS04CPkRq4Ldg%3D%3D"></' + 'script>');

Below is one custom javascript function which I want to execute in body load event

<script type="text/javascript">  
function ApplyFormat()
var meetingWPDIV = document.getElementById("MeetingWebparts");
if (meetingWPDIV != null) {
if (meetingWPDIV.innerText.indexOf("This Web Part was designed for use on a Microsoft Meeting Workspace") < 0) { = "";

Here is how body tag of master page looks like which handles the method calls using init.js file and based on the functions added in spBodyOnLoadFunctionNames.

<body scroll="no" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master">

The above JavaScript function ApplyFormat() is added in _spBodyOnLoadFunctionNames  array. Now when the page load will happen, on the body load event my function ApplyFormat()  Will be executed

Error cause & solution
  • Init.js file reference is missing , to resolve this, check the page source and make sure the init.js file reference is added In the page head tag
  • The JavaScript function which is added in the array  _spBodyOnLoadFunctionNames;  is written before the init.js file reference added in the page.
This is most common mistakes, we add the custom scripts on the top in the head tag and as you know the reference to init.js file is also added in the head tag, so if the custom method added in array _spBodyOnLoadFunctionNames  would not work because init.js file not yet referenced so it is not able to find the definition of _spBodyOnLoadFunctionNames  and so gives script error on the page.
To resolve this error, check the page source and see the line number where init.js reference is added, and now see the custom JavaScript _spBodyOnLoadFunctionNames   code line number, this should be used after the init.js reference is added.

  • The body tag element is not properly defined, check the page source and make sure the body tag is properly defined as given above.