Archive for the ‘SharePoint2010’ Category


Hi, I am a SharePoint front-end developer. As such, it is important to understand the client life cycle in terms of DOM, Browser-engine, etc. We will be talking about the Onload process in this post. There are different techniques used to Provide our custom JavaScript code loaded before / in the middle / alter OnLoad events in SharePoint;

Here we will see 8 different techniques used for the 0nload process. Below are the specified Techniques.

Below are the code snippets for each technique in use.


  1. Sys.Application.add load(SPLoad);
  2. function SPLoad(){
  3.     console.log(“Sys.Application.PageLoad.Time:” + (( – performance.timing.navigationStart))
  4. }


  1. Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(SPPageLoaded);
  2. function SPPageLoaded(sender,args){
  3.     console.log(“Sys.Webforms.PageRequestManager.PageLoaded.Time:” + (( – performance.timing.navigationStart))
  4. }

Document.ready Jquery

  1. jQuery(document).ready(jqueryLoadsSP);
  2. function jqueryLoadSP(){
  3.     console.log(“Document.ready Jquery.Time:” + (( – performance.timing.navigationStart))
  4. }
  5. function ProcessDefaultOnLoad() {
  6.     ProcessPNGImages();
  7.     UpdateAccessibilityUI();
  8.     UpdateAnimationUserControl(false);
  9.     window.setTimeout(‘ProcessImn()’, 10);
  10.     ProcessOnLoadFunctionNames(_spBodyOnLoadFunctionNames);     ProcessOnLoadFunctions(_spBodyOnLoadFunctions);
  11.     if (typeof _spUseDefaultFocus != “undefined”)
  12.         DefaultFocus();
  13. }


  1. _spBodyOnLoadFunctionNames.push(‘OnPageLoad’);
  2. function OnPageLoad(){
  3.     console.log(“_spBodyOnLoadFunctionNames. Time: “ + (( – performance.timing.navigationStart));
  4. }


  1. _spBodyOnLoadFunctions.push(raiseFunc);
  2. var raiseFunc = function(){
  3.     console.log(“_spBodyOnLoadFunction. Time: “ + (( – performance.timing.navigationStart));
  4. };


  1. ExecuteOrDelayUntilScriptLoaded(MyFunction, “sp.core.js”);
  2. function MyFunction(){
  3.     console.log(“ExecuteOrDelayUntilScriptLoaded:sp.core.js. Time: “ + (( – performance.timing.navigationStart));
  4. }

SP.SOD.executeFunc: sp.js

  1. SP.SOD.executeFunc(‘sp.js’‘SP.ClientContext’, sharePointReady);
  2. function sharePointReady(){
  3.     console.log(“SP.SOD.executeFunc: sp.js. Time: “ + (( – performance.timing.navigationStart));
  4. }


  1. ExecuteOrDelayUntilBodyLoaded(delayBody);
  2. function delayBody(){
  3.     console.log(“ExecuteOrDelayUntilBodyLoaded. Time from NavStart: “ + (( – performance.timing.navigationStart));
  4. }




Run 1


Run 2


Run 3




Run 1


Run 2


Run 3


As you see the above images of the output of the code snippet run on both chrome and IE11 browsers, here we discover the sequence of execution.

We will talk about both the sequences,

Order Chrome IE11
1 ExecuteOrDelayUntilBodyLoaded document.ready Jquery
2 Sys.Application.PageLoad. ExecuteOrDelayUntilBodyLoaded
3 document.ready Jquery Sys.Application.PageLoad.
4 SP.SOD.executeFunc: sp.js. SP.SOD.executeFunc: sp.js.
5 _spBodyOnLoadFunctionNames _spBodyOnLoadFunctionNames
6 _spBodyOnLoadFunction _spBodyOnLoadFunction
7 ExecuteOrDelayUntilScriptLoaded:sp.core.js ExecuteOrDelayUntilScriptLoaded:sp.core.js
8 Sys.WebForms.PageRequestManager.PageLoaded Sys.WebForms.PageRequestManager.PageLoaded
  • ExecuteOrDelayUntilBodyLoaded function is always executed first in chrome (but at this stage we cannot access  SP methods). Whereas the document.ready Jquery function is executed first in IE11.
  • This could be useful to execute our custom code at a really early stage in the OnLoad process keeping in mind the order of execution.
  • There are two SharePoint onLoad functions _spBodyOnLoadFunctionNames and _spBodyOnLoadFunction. Always executed in the order. SO, if we want to execute some code after all functions included by us (or other devs) in _spBodyOnLoadFunctionNames, then it is useful to use this one _spBodyOnLoadFunction, because is executed the last.
  • If we want to execute some functions after all functions (SP, after load functions, Yammer, etc.) we can use this function to attach the OnLoad event -> Sys.WebForms.PageRequestManager.PageLoaded.
  • I have referred to an article to implement this particular functionality, check the URL.



In SharePoint SharePoint List Column Person or Group Allow multiple selections after we add multiple user in that column after config list with dataview webpart this column show like Ex. 2; #abc;3;#pqr remove special character using javascript

  1. Ex. 2; #abc;3;#pqr
  2. Ans: abc;pqr
  3. <script type=“text/javascript”>
  4.      function CleanNames(textclean) {
  5.           return text2clean.replace(/[;#0-9]+/g, “; “);
  6.      }
  7. </script>
  8. Then call it from your XSL
  9. <xsl:if test=“string-length(@Employess) != 0”>
  10.      <script type=“text/javascript”>document.write(CleanNames(“<xsl:value-of select=“@Employess” />“));</script>
  11. </xsl:if>
In Sharepoint 2010 Dataview Webpart Create Trim Function for Multiline Texbox in xslt expresion.
for example:
SharePoint multi line text box column
O/p: SharePoint multi line text…….
  1. <xsl:value-of select=“concat(substring(@Description,1,180),’…’)/”>
  2. </xsl:value-of>


This code describe how to create web part custom properties in SharePoint 2010.



  1. [Browsable(true),Category (“Miscellaneous”),DefaultValue (“ListName”),
  2. WebPartStorage(Storage.Personal),
  3. Friendly Name(“ListName”),Description(“Text Property”)]
  4. Public string ListName
  5. {
  6.      get
  7.      {
  8.           Return  strList;
  9.      }
  10.      Set
  11.      {
  12.           strList=Value;
  13.      }
  14. }

2. CheckBox

  1. [Browsable(true),Category (“Miscellaneous”),DefaultValue (false),
  2. WebPartStorage(Storage.Personal),
  3. Friendly Name(“NeedCheckBox”),Description(“Checkbox Property”)]
  4. Public bool NeedCheckBox
  5. {
  6.       get
  7.       {
  8.             Return  boolCheckBox;
  9.       }
  10.       Set
  11.       {
  12.             boolCheckBox =Value;
  13.       }
  14. }

3. RadioButton

  1. [Browsable(true),Category (“Miscellaneous”),DefaultValue (true),
  2. WebPartStorage(Storage.Personal),
  3. Friendly Name(“NeedRadioButton”),Description(“RadioButton Property”)]
  4. Public bool NeedRadioButton
  5. {
  6.       get
  7.       {
  8.             Return  boolRadioButton;
  9.       }
  10.       Set
  11.       {
  12.             boolRadioButton;=Value;
  13.       }
  14. }


The Distributed Cache service provides caching features in SharePoint Server 2013. The microblog features and feeds rely on the Distributed Cache to store data for very fast retrieval across all entities. The Distributed Cache service is built on Windows Server AppFabric, which implements the AppFabric Caching service. Windows Server AppFabric installs with the prerequisites for SharePoint Server 2013. The Distributed Cache service provides in-memory caching services to several features in SharePoint Server 2013. Some of the features that use the Distributed Cache service include:

  • Newsfeeds
  • Authentication
  • OneNote client access
  • Security Trimming
  • Page load performance

In SharePoint Server 2013, there are several caches that exist, all of which depend on the Distributed Cache service.

Different caches that depend on the Distributed Cache service as indicated in the following table:

Name Cache Name Description
Login Token Cache DistributedLogonTokenCache
Feed Cache DistributedActivityFeedCache This cache stores activities and conversations for use by the feeds on a user’s My Site.
Last Modified Time Cache DistributedActivityFeedLMTCache This cache stores time stamp information for all Feed Cache entities.
OneNote Throttling DistributedBouncerCache
Access Cache DistributedAccessCache
Search Query Web Part DistributedSearchCache
Security Trimming Cache DistributedSecurityTrimmingCache
App Token Cache DistributedServerToAppServerAccessTokenCache
View State Cache DistributedViewStateCache
Default Cache DistributedDefaultCache This cache can be used by any feature.

The microblog features and feeds rely on the following two caches: the Last Modified Time Cache and the Feed Cache.

  • Feed Cache: The Feed Cache stores recent activities and recent conversations for all entities.
  • Last Modified Time Cache: The Last Modified Time Cache is used to determine the last modified time for all items in the Feed Cache.

Source: Overview of microblog features, feeds, and the Distributed Cache service in SharePoint Server 2013.


When you create a new web part page in SharePoint, its left navigation column becomes empty. The reason for this is that the left side navigation is defined in the Master Page using the “PlaceHolderLeftNavBar” content place holder and templates for Web Part Pages shipped with SharePoint and overrides this content place holder and deletes its content, thus displaying empty left navigation.

The solution for this is to change the page so it will not override the menu place holder, but inherit it from the Master Page. The place holders we are interested in are:


  1. There is this tag that needs to be deleted or commented (this one hides the left nav):

    tag for deleted or commented

  2. Delete only this tag since this is what overrides the default nav coming from the master page.


  3. Leave this tag as it is, if this is deleted (as said in other posts) it leaves a blank row on top of the left nav which is not what you would want.

    content place holder

  4. Save the file.

You will get a warning saying you are about to customize the page. Just go ahead and open that web part again. It should have that good left navigation.


This is a very common issue faced by 9 out of 10 SharePoint developers. The custom site Logo is not reflected on the Web Part Page and hence the default logo is seen as shown in the screenshot:

Home Page

sharepoint home page

NewTestPage (WebPartPage)

new test page in sharepoint

  1. Go to the Web part (NewTestPage) page.
  2. Click on the “Page” tab at the top, click on the “Title Bar Properties” at the right (in the ribbon).

    page title bar

  3. In the Image Link section on the right, paste in the image URL:

    image url

  4. Click OK.

Out Page: Web part Page

new test page


In this blog we explore to retrieve large number of items with a better performance we can either user SPQuery or PortalSiteMapProvider Class. Read more with examples. Retrieving large number of items from SharePoint List.

If you have to retrieve a large number of items and also need a better performance then you should use one of the method below:

  • Using SPQuery
  • Using PortalSiteMapProvide

Let’s see the example for both the method


  1. using (SPSite CurrSite = new SPSite(SPContext.Current.Web.Url))
  2. {
  3.    using (SPWeb CurrWeb = CurrSite.OpenWeb())
  4.    {
  5.        SPQuery curQry = new SPQuery();
  6.        curQry.Query = “<Where><Eq><FieldRef Name=’Dept’/> <Value Type=’Text’>Sharepoint</Value></Eq></Where>”;
  7.        curQry.RowLimit = 100;
  8.        SPList curList = CurrWeb.Lists[“Dept”];
  9.        SPListItemCollection curItems = curList.GetItems(curQry);
  10.        foreach (SPListItem curItem in curItems)
  11.        {
  12.            string ResultTitle = curItem[“Title”].ToString();
  13.        }
  14.    }
  15. }


The Class includes a method called GetCachedListItemsByQuery that retrieves data from a list based on an SPQuery object that is provided as a parameter to the method call.

The method then looks in its cache to see if the items already exist. If they do, the method returns the cached results, and if not, it queries the list , store the results in cache and returns them from the method call.

  1. //Get Current Web
  2. SPWeb curWeb = SPControl. GetContextWeb(HttpContext.Current);
  3. //Create the Query
  4. SPQuery curQry = new SPQuery();
  5. curQry.Query = “<Where><Eq><FieldRef Name=\’Category\’/><Value Type=\’Text\’> Sharepoint </Value></Eq></Where>” ;
  6. //Get Portal Map Provider
  7. Portal SiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
  8. PortalWebSiteMapNode pNode = TryCast (ps.FindSiteMapNode (curWeb. ServerRelativeUrl), PortalWebSiteMapNode);
  9. //Get the items
  10. Pltems = ps.GetCachedListItemsByQuery (pNode, “Dept”, curQry, curWeb);
  11. //Enumerate all resulting Items
  12. foreach(PortalListItemSiteMapNode curItem in pItems)
  13. {
  14.    string ResultItemTitle = curItem[“Title”]. ToString();
  15. }

In this blog, let us discuss how to upload a custom list template and about creating a list based on this custom template, in SharePoint 2013, using PowerShell.

# Adding the PowerShell Snapin
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
# Get the SiteURL
$site = get-spsite(“http://SiteCollectionURL/&#8221;)
# Get the root web
$web = $site.RootWeb
# Get the list template gallery
$spLTG = $web.getfolder(“List Template Gallery”)
# Get the list template gallery Collection
$spcollection = $spLTG.files
# Get the custom list template file
$Templatefile = get-item “C:\Custom_list_template.stp”
# Add the custom list template file to gallery
$spcollection.Add(“_catalogs/lt/Custom_list_template.stp”, $Templatefile.OpenRead(), $true)
Write-Host “Custom Template Uploaded to List Template Gallery Successfully”
Write-Host “Creating the List based on the Template”
# Get the custom list templates
$CustomlistTemplates = $site.GetCustomListTemplates($web)
#Create the custom list using template
$web.Lists.Add(“Custom_list”, “Custom list”, $CustomlistTemplates[“Custom_list_template”])
Write-Host “Based on the template List Created


The web site uses a large number of user controls hard coded across twenty-odd page layouts–a big no-no. While we’ve matured as a dev. team since this site launched and now fully appreciate the value of web parts and a small set of key page layouts, unfortunately the site is live as-is.

From a production support perspective we’re still working on the site and adding new user controls here and there. This shouldn’t be problematic but MOSS, in its infinite wisdom, limits the number of user controls on a page and fails when that limit is reached.

Server Error in Application

When developing large portals, it can often be a mistake. associated with exceeding limit inclusion in external objects, such as pages, .ascx files.

This problem can easily be corrected by editing the Web.config file. For this limit corresponds to the parameter DirectFileDependencies.

If you insert more than 10 user controls in a masterpage, you might get an error similar to this:

The page ‘/path/somefile.master’ allows a limit of 11 direct dependencies, and that limit has been exceeded.

You can easily increase that limit as it is actually set in your sharepoint web.config:

Steps edit web.config

  1. Browse to C:\inetpub\wwwroot\wss\VirtualDirectories\

    Browse Folder

  2. Open the folder corresponding to your Sharepoint website.
  3. Edit the file web.config
  4. Do a search for “safemode“.
  5. Change the property DirectFileDependencies from 10 to a value your choice.
  6. Do an iisreset command and you’re done!

< SafeMode MaxControls = “200” CallStack = “true” DirectFileDependencies = “20” TotalFileDependencies = “50” AllowPageLevelTrace = “false” >

The solution is to simply increase the value to the desired value.