Friday 3 February 2017

Javascript to trigger Connect to Outlook feature in SharePoint 2013

Adding this custom button, they do not need to access to the calendar page and hit on the SharePoint Ribbon button.
To achieve this function, firstly, you need to know how to mock the original Connect to Outlook button javascript.
A little digging tells us that there are a few options/properties we need to configure including:
base-urlhttps://www.nothingbutsharepoint.com/Calendar
list-url/Lists/SharePointEvents/
guid???????
site-nameNBSP Calendar
list-nameSharePointEvents
script src="http://code.jquery.com/jquery-1.6.1.min.js">
script language="javascript" type="text/javascript">
  function replaceURL() {
    $('#outlookLink').attr('href','stssync://sts/?ver=1.1&type=discussions&cmd=add-folder&base-url=http://dev-dc01-spweb:90&list-url=http://dev-dc01-spweb:90/Documents/Forms/AllItems.aspx&guid=%7B49D380A2-EBF2-40E0-99DF-9916AC51B003%7D&site-name=http://dev-dc01-spweb:90&list-name=Documents');
  }

  _spBodyOnLoadFunctionNames.push("replaceURL");
/script>
a id="outlookLink" href="#">Link to Outlook



folder-type

Required. Can be calendar or contacts,Documents,discussions

Stssync Protocol

Windows SharePoint Services 3
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
The stssync protocol enables you to add an Events list or a Contacts list that exists on a Windows SharePoint Services site to Microsoft Office Outlook 2007 or to a third-party application that supports the protocol.
stssync://sts/?ver=version&type=folder-type&cmd=command-name&base-url=sts-url&guid=the-guid&site-name=site-friendly-name&list-name=list-friendly-name&list-url=list-url&user-id=uid
version
Required. The version of the application in the format x.y. For example, for Outlook, the value of this parameter should be 1.0. The values x and y must be composed of numbers only. x must not start with a zero, and y must be either zero or some other sequence of digits that does not start with a zero.
NoteNote
x and y cannot be more than two digits each; otherwise Outlook considers the URL to be malformed. A third-party client application may or may not use this parameter, but when the URL is constructed, the parameter must have a value—otherwise the URL is considered malformed.
folder-type
Required. Can be calendar or contacts, depending on the type of SharePoint list being added to Outlook or to a third-party application. This parameter is case-insensitive.
command-name
Required. The command name that Outlook or the third-party application understands. Specify add-folder to add a folder to Outlook. More commands may be added to Outlook later.
sts-url
Required. The URL to the SharePoint site being added. Should not end in a / character.
the-guid
Required. The GUID that, when paired with the sts-url parameter, uniquely identifies a SharePoint list. Outlook expects this parameter to be in the following format: "{"+ 8 hexadecimal characters + "-" + 4 hexadecimal characters + "-" + 4 hexadecimal characters + "-" + 12 hexadecimal characters + "}". If this parameter is in a different format, Outlook considers the URL malformed and returns an error.
site-friendly-name
Required. The display name of the site containing the list that is being added. Outlook uses this parameter to create the folder name.
list-friendly-name
Required. The display name of the list that is being added. Outlook uses this parameter to create the folder name.
list-url
Required. A string that is added to the sts-url parameter to create the full URL for the list. Should start with a / character.
uid
Optional. A number greater than zero, with fewer than eight digits. Uniquely represents a user on the SharePoint site.

Notes


  • Special character escaping: If any of the characters "&", "\", "[", "]", or "|" is part of the value of the sts-urlsite-friendly-namelist-friendly-name, or list-url parameter, it must be preceded by a "|" character. For example, a list-friendly-name of Dan [Wilson] - Business\Personal Contacts would become Dan |[Wilson|] - Business|\Personal Contacts.
  • The sts-urlsite-friendly-namelist-friendly-name, and list-url parameters can contain Unicode characters. However, the Unicode characters must be enclosed in brackets "[ ]" and must be 4-digit hexadecimal character representations of the Unicode characters.
  • To implement a third-party client that can make use of the stssync protocol to add and synchronize Events and Contacts lists that exist on a SharePoint site, you typically need to implement an ActiveX control named StssyncHandler and provide support for the stssync protocol. The third-party client typically needs to be able to decode the URL and synchronize the Contacts or Events list on the SharePoint site. You can use the Microsoft.SharePoint namespace or the Web services exposed by Windows SharePoint Services to perform this task. You also need to register the stssync protocol in the registry with the name of the executable file of your application. In Microsoft Windows operating environments with Internet Explorer version 5.0 or later, you can use the sample provided below. Copy the following lines to a .reg file, and replace  with the path to the executable file of the application that wants to synchronize events and contacts with Windows SharePoint Services. Then double-click the .reg file to register the stssync protocol on your computer.
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\stssync]
    @="URL:Add SharePoint Folder"
    "URL Protocol"=""
    
    [HKEY_CLASSES_ROOT\stssync\shell]
    @="open"
    
    [HKEY_CLASSES_ROOT\stssync\shell\open]
    @=""
    
    [HKEY_CLASSES_ROOT\stssync\shell\open\command]
    @=" \"%1\""
    
    For information about the StssyncHandler control that is installed on the client computer during Microsoft Office setup, see StssyncHandler Control.

Example


stssync://sts/?ver=1.0&type=calendar&cmd=
add-folder&base-url=http%3A%2F%2Fspserver1&list-url=
%2FLists%2FEvts%2FAllItems%2Easpx&guid=
%7BAA7D945C%2DE5C3%2D4854%2DB631%2D10A98E711E2B%7D&site-
name=Share|%7CPoint%20|%5BSite|%5D&list-name=Ev[00E900F1]ts
This URL is for a list named "Evéñts" on a site named "Share|Point [Site]" with site URL http://spserver1 and list URL http://spserver1/Lists/Evts/AllItems.aspx. Note the use of the vertical bar to escape the "|", "[", and "]" characters, and the hexadecimal representation of the two Unicode characters in the list name.