Sunday, December 7, 2014

When you are hit with a problem in SharePoint 2013 you get notified to use a correlation id to check for further details in the trace logs (ULS logs).

So you hopefully start up ULS Viewer and open up the relevant logs and search like a mad man after this specified correlation id. Sometimes you don’t find the provided correlation id in the log file you opened. Is there a easier way?

Yes and that is to use the SharePoint PowerShell command Merge-SPLogFile. According to the description of Merge-SPLogFile on Microsoft TechNet:
“Combines trace log entries from all farm computers into a single log file on the local computer.”
Let me explain how you can use this powerful command.
Basic Usage
Lets visualise a simple farm.

As the example Farm image above we have two frontend servers, application server and database server. If I wanted to consolidated the last hour of SharePoint log entries from the front-end server and application server I would open up SharePoint Management Shell on one of the servers and type the following command:
Merge-SPLogFile –Path “E:\SPLogs\MergedLogs.log” –Overwrite

Now that was a very basic example to merge the various servers log files. More parameters are available on theMicrosoft TechNet article for Merge-SPLogFile. For example Area, Category, Level, Message, StartTime, EndTime and more.
Finding Correlation ID
What the following example show is how to find the log entries for a specific correlation id:
Merge-SPLogFile –Path “S:\SPLogs\MergedLogs.log” –Correlation 3ae2a6c0-da14-43a1-afda-5bb6bbff3d43 -Overwrite

Since the log files are merged with just the specified correlation id you can load the log file in ULS Viewer to easily view the entries. Please be aware that the log can be empty if the logging level is set to low for the SharePoint category. Just go to SharePoint Central Administration to increase the logging level.

As you can see in the image above the correlation id has 19 matching entries in the log file. Much less log entries to scroll through.
I hope this helps you on finding SharePoint errors quicker and easier. Let me know what your favourite commands and tools are for debugging SharePoint.

Thursday, July 31, 2014

Accessing the SSL Certificate with thumbprint rather than SignInCertificate Name

Use the below code to access the ssl certificate from its certificate store in Custom STS

public static X509Certificate2 GetCertificateByThumbprint(string thumbprint)
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            X509Certificate2Collection certificates = null;

                certificates = store.Certificates;

                var certs = certificates.Find(X509FindType.FindByThumbprint, thumbprint, false).OfType<X509Certificate2>().ToList();

                if (certs.Count == 0)
                    throw new ApplicationException(string.Format(Constants.ExceptionMessages.msgNocertificate, thumbprint));
                else if (certs.Count > 1)
                    throw new ApplicationException(string.Format(Constants.ExceptionMessages.msgMultipleCertificates, thumbprint));

                return new X509Certificate2(certs[0]);
                if (certificates != null)
                    for (var i = 0; i < certificates.Count; i++)
                        var cert = certificates[i];


Note:- never copy and paste the thumbprint directly. Type the value in the web.config. While typing remove the white spaces.

Gigya Authentication process

Gigya is a third part service provider which can let you manage the authentication providers like google, facebook, yahoo, etc..

To have it in your sharepoint follow below approach to authenticate the user using gigya.

Configuration need to be done in below steps
  1. Create apps in provider sites.(Refer Gigya site)
  2.  Crete an app in Gigya site and use the app key, secret key of the provider site to configure Gigya App. (Refer Gigya site)
  3. Configure Social Network Application Keys in Gigya app. (Refer Gigya site)
  4. Create STS to authenticate to SharePoint site by getting the user information from Gigya app.
  5. Export the SSL certificate with/without private key
  6. Registering the SSL certificate using PowerShell commands.

Wednesday, July 9, 2014

At times you may get a requirement to create a page which can accessible by anonymous users also. for example to provision the user to change their password or to log-in to the site. In that case you may have to go for creating a page where user can perform this kind of actions. To create such page you cannot use the default LayoutsPageBase base class for your page because it would trigger SharePoint to prompt anonymous users to log on.
Instead, you need to use another base class for your anonymous application page calledUnsecuredLayoutsPageBase. You can find its MSDN reference at:

Your page class would look like this:
public partial class ApplicationPage1 : UnsecuredLayoutsPageBase
    protected void Page_Load(object sender, EventArgs e)

Remote Interfaces permissions - item not deleting

SharePoint Access Denied DialogSharepoint provides two ways a user can delete an item from any list:
  1. From “Delete Item” menu option available in ribbon
  2. From “Delete Item” menu option available in the item’s context menu
Now you may think that both these options are just alias of one another, i.e. do the same thing the same way which is to delete the item, and must be implemented the same way.
But that is not the case. Both are implemented differently, i.e. both these options use different route of accessing the delete functionality on server. The context menu option uses remoting where as the ribbon option doesnot. So due to this, though you may have given “Delete Items” permission on the list, you need to provide one more permission, “Use Remote Interfaces”, to allow successful deletion from delete item option available from an item’s context menu. Not providing this second permission would lead to a condition where in the user would be able to delete items from “Delete Items” link available in Ribbon, but trying to delete an item from that item’s context menu would lead to an “Access Denied” error message.
Thus, when ever you find yourself into the situation where in the delete from ribbon is working but the same from context menu is giving error, go to the permission level that apply to the list or that item, provide “Use Remote Interfaces” permissions, MISSION ACCOMPLISHED.

Tuesday, June 10, 2014

Enable Sharepoint js intellisense

I know most of you people find it difficult to add intellisense to visual studio 2012. 
Follow the below steps to get it working . 

It works like a charm in JavaScript file for SharePoint hosted app:


It works for all my apps. I don't have to reference SharePoint JavaScript API for each new app.

How it works
1. copy the path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\SP.debug.js"

2. Open Visual Studio and clicked on TOOLS->Options

3. Click on Text Editor -> JavaScript ->IntelliSense -> References

4. Add the sp.debug and clicked on "OK".

Thursday, May 22, 2014

Difference Between .dwp and .webpart

    1. Dwp was the file extension used in version 2 of SharePoint and .webpart is a new extension used in version 3
    2. Version number on the xmlns attribute is different [2->2003, 3-> 2007]
    3. The main difference is that all properties passed to the web part are specified with a property element and a name attribute in version 3. Version 2 uses different element names for everything.

Monday, May 12, 2014

Workaround for Lookup field in SharePoint list templates

  1. Download the "Template-Actors.stp" file from "List Templates"
  2. Rename the file and change the extension of the file from ".stp" to ".cab"..
  3. Once you have the extension as ".cab", extract the "Manifast.xml" file.
  4. Get the list url of the lookup list and replace the guid with th url.
  5. Save the manifest.xml
  6. Open a VS.NET command prompt.
  7. Run the makecab command as follows:
  8. makecab manifest.xml [yourlist].stp
  9. Import the new STP into the destination Web’s list template gallery. You will need to delete it if it has previously been imported.
  10. Create a new list based upon the new STP file.

The lookup column on the new list should retain all the data that was in the source list.

Error while updating the farm credentials.

I was getting the below error when i am trying to update the farm credentials using stsadm command in sharepoint 2010.
Value cannot be null.
Parameter name: farm
I got it because I had SQL Server (SHAREPOINT) not running. I have just started and ran the same command and it worked.
stsadm -o updatefarmcredentials -userlogin XXX -userpassword XXX

Wednesday, April 23, 2014

Unable to see save as site template

If your unable to see save as site template below might be the reason for that.

You save a Team site as a template with or without the SharePoint Server Publishing Infrastructure feature activated at the site collection level.
  • Do not activate the SharePoint Server Publishing feature at the site level otherwise the Save site as template option will not be available.
  • By default the Save site as template option is available even if the SharePoint Server Publishing Infrastructure feature is enabled at a site collection level.

Tuesday, April 15, 2014

Cross Site Lookup

Hi Guys,

Today I am going to tell you how to use the jslink for cross site lookup. Recently we got a requirement in our project to create field which looks up the values from different site collection. For that I created 2 components

  1. JSLink for new and Edit form.
  2. Custom service which return the data in the form of json from the specified site collection, list, field.
Below is the screen shot how the Project (Single Line of text) will be rendered like lookup field

(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Project': {
            'NewForm': RenderCrossSiteLookup,
            'EditForm': RenderCrossSiteLookup,
var currentval = "";

function RenderCrossSiteLookup(ctx) {
    var formCtx = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    currentval = formCtx.fieldValue;
    formCtx.registerGetValueCallback(formCtx.fieldName, function () {
        return $("#ddlSourceItems option:selected").text();
    var validators = new SPClientForms.ClientValidation.ValidatorSet();
    if (formCtx.fieldSchema.Required) {
        validators.RegisterValidator(new SPClientForms.ClientValidation.RequiredValidator());
    if (validators._registeredValidators.length > 0) {
        formCtx.registerClientValidator(formCtx.fieldName, validators);
    formCtx.registerValidationErrorCallback(formCtx.fieldName, function (errorResult) {
        SPFormControl_AppendValidationErrorMessage('ddlSourceItems', errorResult);

    var ddlHtml = "<select id='ddlSourceItems' style='width:160px;'></select>";

    return ddlHtml;
function CrossSiteLookupService() {
        dataType: "json",
        url: "http://<Your Site collection>/_vti_bin/CrossSiteLookupWCF/CrossSiteLookup.svc/GetItems?ListUrl=Lists/Projects%20List&siteUrl=<Site Url from where the data to be pulled>&LookupField=Title",
        success: success

function success(response) {
    $json = $.parseJSON(response.GetItemsResult);
    var opt = "<option value=''></option>";
    $.each($json, function (i, item) {
        if (currentval != "" && item.Title == currentval) {
            opt += "<option selected='selected' value='" + item.ID + "'>" + item.Title + "</option>"
        else {
            opt += "<option value='" + item.ID + "'>" + item.Title + "</option>"


function loadScript(url, callback) {
    var script = document.createElement("script")
    script.type = "text/javascript";
    if (script.readyState) { //IE
        script.onreadystatechange = function () {
            if (script.readyState == "loaded" || script.readyState == "complete") {
                script.onreadystatechange = null;
    } else { //Others
        script.onload = function () {
    script.src = url;

loadScript("http://<Your Site Collection>/SiteAssets/Scripts/jquery.min.js", function () {

Sunday, April 6, 2014

What is a Correlation Token ?

A workflow instance interacts with several SharePoint objects (task lists, and documents or items) during its lifetime. In SharePoint, you can have many workflow instances running at the same time and interacting with several objects at the same time. To be able to identify which workflow instance is interacting with which object, you must use an identifier that links one particular workflow instance to one particular SharePoint object. Each workflow instance must be bound to its own items. Such an identifier is called a Correlation Token. A correlation token links a workflow instance to its documents, items, and tasks. It prevents confusion between different workflow instances. We need have one correlation token for the workflow and one for each task we create during the workflow, so that when a user completes a task we have a unique identifier with which to receive any input from the user into the workflow. Make sure correlation token names are not repeated in different task.