Thursday, February 23, 2017

SharePoint 2010/2013 Display user information using ProfilePropertyLoader

Hi Folks,

This article talks about the best way to get the user profile properties on page.

Sometimes we come across the requirement asking to show the User related information on the page.
Generally we write code by accessing User Information list to get the User related data.

In such cases, rather than writing code SharePoint gives us the provision to read the User data.

SharePoint has something called "ProfilePropertyLoader" control which will be available in any SharePoint page which has the below register tag.

<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Follwing are the tags we need to add to the page inoder to read the current user Name and Email.

User Name
The first line below is needed to load and make the profile properties available.

<SPSWC:ProfilePropertyLoader runat="server"/>

<SPSWC:ProfilePropertyValue PropertyName="FirstName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

<SPSWC:ProfilePropertyValue PropertyName="LastName" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>

Email
<SPSWC:ProfilePropertyValue cssClass="loggedin" PropertyName="WorkEmail" ApplyFormatting="False" runat="server" ShowPrivate="True" PrefixBrIfNotEmpty="False"/>


Hope this helps...

RELATED POST: How to get current user info using jquery spservices



SharePoint site performance improvement techniques - SharePoint2010/2013 and SharePoint Online

Hi Friends,

In this article we will talk about the Steps to Optimize SharePoint Performance.

This article covers some of the factors which plays a vital role in the performance of the SharePoint site on a high level.

1)    Code optimization


  •  Server side code - Use optimized methods, SPDisposeCheck etc.,


Poor Performing Methods and Properties
Better Performing Alternatives
SPList.Items.Count
SPList.ItemCount
SPList.Items.XmlDataSchema
Create an SPQuery object to retrieve only the items you want.
SPList.Items.NumberOfFields
Create an SPQuery object (specifying the ViewFields) to retrieve only the items you want.
SPList.Items[System.Guid]
SPList.GetItemByUniqueId(System.Guid)
SPList.Items[System.Int32]
SPList.GetItemById(System.Int32)
SPList.Items.GetItemById(System.Int32)
SPList.GetItemById(System.Int32)
SPList.Items.ReorderItems(System.Boolean[],System.Int32[],System.Int32)
Perform a paged query by using SPQuery and reorder the items within each page.
SPFolder.Files.Count
SPFolder.ItemCount


  • CSOM - Keep ExecuteQuery function call as less as possible.
Also request properties whichever required. Ref below example

var userObj = clientContext.Web.CurrentUser;
clientContext.Load(userObj, user => user.Title, user => user.LoginName);




  • Use caching in Code (Both CSOM and Server Side). Use the cache duration depends on how often the block of code changes the data.

2)    Merge JS files to single wherever possible.

3)    Make JS files to minified (min) files.

4)    Reduce the usage of global variables in JS files.

5)    Merge CSS files to single wherever possible.

6)    Use CDN(Content Deployment Network) deployment of JS, CSS and Images.

Note: Using CDNs only makes sense in a SharePoint Online context and should be avoided with SharePoint Server.


Hope this helps...

Wednesday, February 22, 2017

Scroll to top of the page after Pagination or Refinement in SharePoint 2013 search results

Hi Friends,

In SharePoint out of the box search results, the paging control will be under the Search results. In this case, whenever there is paging happened the SharePoint will keep the page remained at the bottom though it moved to next set of results. This make users to scroll up the page in order to see the next set of results.


We can overcome this approach using "ScrollToTopOnRedraw” property in Search results webpart. This is a hidden property which will not be visible in Edit webpart properties UI. However this change can be done by modifying the  .webpart file.

"ScrollToTopOnRedraw" is a boolean property which is false by default and all we need to do is, setting this property true.

Please find the below steps

1) Export your current search results webpart to get .webpart file

2) Open it in a text editor or Notepad

3) Find the property “ScrollToTopOnRedraw” and change its value from False to True and Save the file.

4) Import the webpart and add it in your page.

Thats All. The page scrolls to top whenever there is pagination or refinement.

Hope this helps...

Popular Posts