SharePoint 2013 : Working with Chrome Control and Cross Domain Execution in Provider Hosted App

In the new SharePoint 2013 App model, the Apps can be hosted in one of the following hosting model: SharePoint Hosted (with in SharePoint Domain), Provided Hosted and Auto Hosted (Outside SharePoint Domain).

One of the biggest issue that we can see with Apps running outside SharePoint Domain is Branding, since these Apps has got separate Home or Landing Pages than SharePoint and does not follow Visual Paradigms like Navigation Menus, Back Link to Home Page and so on similar to SharePoint.

Intranet Users can feel disconnected with the App due to this huge gap in UI Experience.

In order to overcome this obvious issue SharePoint allows to import a very basic version of SharePoint 2013 Chrome into their Apps without apply the Custom CSS Styles manually by means of a Client Side Rendering Control called “Chrome Control”.

The functional implementation details of this control reside in “SP.UI.Controls.js” file located in the new “/_layouts/15” virtual directory or “Layouts” Folder in 15 Hive.

Hope up to this point you grasp a fair understanding in Chrome Control and now it is time to move on to see it in action.

In order to demonstrate this implementation of Chrome Control we will start with a Provider Hosted App as show in below steps:

Create a new SharePoint App Project by selecting “App for SharePoint” project template

1

Choose Hosting Model as “Provider-Hosted”

2

Choose “ASP.Net Web Forms Application” as template for provisioning the Remote Site

3

Specify the Certificate location, decrypting password and Issuer ID (This ID was generated while we configure the S2S Trust for Provider Hosted Apps)

4

Once the Project has been added to the solution it would look like as below:

5

I have added a dummy feature to force SharePoint to create an App Web for this App, though this is purely optional.

6

We can review the App Web using any SharePoint Object Browser, here I am using SharePoint Manager to lookout the same

7

Also notice that we have changed the Start Page for App to “ChromeCrossDomain.aspx” as highlighted below-

8

Allowing Read permission for the App in Site Collection Hosting it in AppManifest.xml

9

Also in the Remote Web Project we have Pages Folder which is containing pages for our App.

10

We have “ChromeCrossDomain.aspx” page residing inside this folder which will serve as Start Page for this App

11

Similarly we have Scripts folder which is holding all JavaScript Files in use by this App as shown below

Apart from standard JavaScript Files supporting JQuery, we also have two App specific custom JavaScript Files “ChromeLoader.js” & “CrossDomainExecutor.js” which is implementing the core of Chrome Control for this App

12

In the Start Page HTML –

Firstly we have to add the “Script” Tags to include custom Javascript Files

Then we need to add a “Div” Tag with id = “chrome_ctrl_container” (you can use any unique value as ID) at the top level as shown highlighted

13

Now if we explore the code in one of the Custom JS file “ChromeLoader.js”, we can see it as

Step 1 – “getParameterByName” is a helper function that can be utilized to read Query String Parameters from the incoming request

Step 2- Read the “SPHostUrl” Query String Parameter to get the handle on Host Web

Step 3- Load “SP.UI.Controls.js” file in context of Host Web and once loaded call “renderChrome” method

Step 4- Inside “renderChrome” method, we are preparing Object holding the Chrome Configuration Options

appIconUrl                –      Icon URL that we need to show at the top header of the App

appTitle                     –      Header Title for the App

appHelpPageUrl       –      Help Page Url for the App

settingsLinks            –      Links to be shown under settings menu

Step 5- “SP.UI.Controls.Navigation” method is used to load the Chrome Control inside the div with Id = “chrome_ctrl_container” along with settings applied based on the “options” object we created in Step 4

Step 6- Visible the Chrome Control and let the SharePoint UX rendering takes precedence over the App defaults

14

This is it for loading the Chrome Control in our custom App.

Now let see how we can enable Cross Domain Execution for this App.

If we investigate the other custom JS File “CrossDomainExecutor.js” we can notice the execution as follows-

Step 1- Getting “SPHostUrl” and “SPAppWebUrl” Query String Parameters using “getParameterByName” method as before. “SPHostUrl” provides the Url of Host Web where the App has been installed while “SPAppWebUrl” provided the Url of App Web which we got created during the App Installation (by means of Dummy Feature).

Step 2- Getting the reference of “SP.RequestExecutor.js” JS file in context of Host Web as earlier. “SP.RequestExecutor.js” is used to execute Cross Domain Calls to SharePoint i.e. the Call from SharePoint App (Domain 1) to SharePoint (Domain 2).

Step 3, 4, 5- Instantiating the context of App Web and instantiating the object of AppContextSite to get the handle on Host Web object. Once it is done rest of the things are simply applying JSOM operations

Step 6- Query Announcements List in Host Web and interface its records in the App Start Page

15

Before moving forward let’s have a look into the Announcements List to see what all items we have for query on App Start Page

16

We can see there are two items available to be displayed with in the App Start Page.

Build the Solution and deploy it

Trust the Security Certificate and move on

17

Trust the App when asked to and move on

18

Provide Credentials for Authentication

19

And we are all set with final outcome which can we analyzed as below:

Step 1- Showing the App URL ensuring we are looking at the Start Page of the App

Step 2- Showing App Site Header Image and Title fetched by Chrome Control from within the Host Web Context

Step 3- Showing Settings Links added during configuring options for the Chrome Control

Step 4- Showing Announcement List Items queried from the Host Web executed by Cross Domain Request to SharePoint

20

So it is evident that by making use of Chrome Control we could save significant efforts in maintaining Synch between SharePoint and App UI Designs.

Hope you find it helpful.

Advertisements

SharePoint Developer Tools – Get Your Gears

There are quite a number of Must to Have developer tools that every SharePoint Developer must have in its arsenal in order to boost its own Productivity while developing solutions on SharePoint Platform.

Few of the tools which are my personal favorites also are listed below:

CAML Designer 2013

CAML Designer can generate the CAML Query Stubs based on the inputs provided by the developer and can quickly give a handle on even complex query formations.

It is not just about the Formation of Queries but also offers code Transition from actual CAML Query to

  • Corresponding Server Side Object Model Code
  • Corresponding Managed Client Side Object Model Code
  • Corresponding JSOM & REST API Calls
  • Corresponding PowerShell Code

1

Download Path: http://biwug-web.sharepoint.com/SitePages/Caml_designer.aspx

SharePoint Manager 2013

SharePoint Manager has got quite a simple and intuitive interface which allows you to quickly and easily navigate down the farm and investigate settings, properties, schema XML and so on. Most of the things in your SharePoint environment can be investigated from this tool.

This tool allows you to quickly navigate the Site Hierarchy and objects, and you can also get a quick handle on Schema of List, Fields and on object properties like Object GUIDs, Object Titles and so on.

2

Download Path: http://spm.codeplex.com

ULS Viewer

ULS Viewer allows you to look into the SharePoint ULS Logs in real time by parsing the Logs. The information (Correlation ID, Date Time Stamp, Event Source Process and so on )exposed by this tool is really useful for productive debugging capabilities.

3

With the evolution of SharePoint 2013 Developer Dashboard also includes these capabilities of reading & parsing ULS logs. Developer Dashboard contains a separate tab by the name “ULS” where we can see the ULS log entries.

4

Download Path: http://www.microsoft.com/en-in/download/details.aspx?id=44020

CKS Dev

CSK Dev is a Visual Studio extension which adds a bunch of new Project items for SharePoint Projects that are really helpful in increasing productivity of a developer.

Extension Project Items included

  • WCF Service SPI template
  • Contextual Web Part SPI template
  • Branding SPI Template
  • ASHX SPI template
  • Upgrade Solution Step
  • Restart IIS Step
  • Copy To SharePoint Root Step

And many more…

5

6

Download Path: http://visualstudiogallery.msdn.microsoft.com/cf1225b4-aa83-4282-b4c6-34feec8fc5ec

Color Palette Tool for Branding

Color Palette allows you create a composed looks for SharePoint 2013.

7

Download Path: http://www.microsoft.com/en-us/download/details.aspx?id=38182

SharePoint 2013 Search Tool

SharePoint Search Tool allows to you create and test SharePoint Search Keyword Query backed up by SharePoint REST API paradigm. It also allows you to analyze the Query Stats and adjust them as per the required output.

8

Download Path: http://sp2013searchtool.codeplex.com/

Fiddler

Fiddler is a Web Proxy that allows to Debug Web Traffic, do Performance Testing, HTTP/HTTPs Traffic Recording, Security Testing and so on.

The use of Fiddler becomes utmost necessary now with the evolution of SharePoint 2013 which is more focused on Development Strategies based on Client Side Scripting Technologies.

9

Download Path: http://fiddler2.com/get-fiddler

SPCAF – SharePoint Code Analysis Framework

SharePoint Code Analysis Framework helps to validate your custom SharePoint Solutions and Apps against Best Coding Practices prescribed the industry drawn by various industry standards.

This framework can be really helpful to let you verify if your custom solutions are Stable, Complying with Company Policies, Following Coding Best Practices, Well Designed and Maintainable and much more.

10

Download Path: http://www.spcaf.com

.NET Reflector from Red Gate

.Net Reflector is one of the best tools I have ever used for understanding code of Third Party DLLs for which I even did not had the Source Code.

Reflector allows you to look into the DLLs to see the code encapsulating inside it to understand its functioning.

11

Download Path: http://www.red-gate.com/products/dotnet-development/reflector/

PowerShell Tools for Visual Studio

This is an excellent Visual Studio Extensions for PowerShell which enables code intellisence for PowerShell Scripts within Visual Studio Editor.

12

Download Path: http://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597

SPFastDeploy

This tool is specially designed to enhance the productivity while working with SharePoint App.

This tool is best suited for pushing the code changes quickly to SharePoint Apps without re-deploying the Apps. This could save a significant amount of time during App Development.

13

Download Path: http://visualstudiogallery.msdn.microsoft.com/9e03d0f5-f931-4125-a5d1-7c1529554fbd

Advanced REST Client plugin for Google Chrome

This is a Chrome Plugin that allows you configure and investigate REST Queries by configuring and executing REST API Call through the tool UI. It also allows us to look for the Stats of the REST Queries in execution.

14

Download Path: https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US

Postman – REST Client plugin for Google Chrome

This is again a Chrome Plugin that allows you deal with REST Calls same as “Advanced REST Client plugin for Google Chrome”.

It is just a matter of choice which one you prefer to work with.

15

Download Path: https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm

SharePoint 2013 Client Browser

This is the similar tool as SharePoint Manager with the only difference that it allows us to connect to SharePoint Sites Remotely using Client APIs. So now no more need to login to SharePoint Server to browser SharePoint Site Objects using this tool.

16

Download Path: https://spcb.codeplex.com/

smtp4dev

This is an awesome tool for testing SharePoint Send Mail Functionalities no matter if it is Custom or OOB functionality that we are testing.

It is used to verify if the SharePoint is sending mails to the recipients properly. This tool intercepts the mails that were sending to the recipients by SharePoint and allows you to view them in its own UI.

17

Download Path: http://smtp4dev.codeplex.com/

PowerGUI

PowerGUI is one of the best tools available for PowerShell Programming. It provides intellisence support for writing PowerShell Scripts at the same time provides lot of useful windows for Debugging purposes.

18

Download Path: http://powergui.org/downloads.jspa

SharePoint Software Factory

The SharePoint Software Factory is a Visual Studio Extension helping SharePoint Beginners, as well as experienced developers to create, manage and deploy SharePoint solutions without having to know schema internals of the SharePoint Artifacts.

19

Following is the list of few of the features offered by this extension-

20

And many more…

For a detailed list of available features you can visit : http://www.matthiaseinig.de/docs/SPSF/OutputHTML/SPSF_RECIPES_INDEX.html

Download Path: https://spsf.codeplex.com/

SharePoint Solution Deployer

SharePoint Solution Deployer helps you to deploy SharePoint solution packages (.wsp) to multiple SharePoint environments. It deploys, retracts and upgrades one or more WSPs and can be extended to perform additional custom tasks in PowerShell before or afterwards.

It provides a simple XML configuration file which allows you to define the deployment environment by using variables i.e. to perform different actions on different URLs depending to which farm you are currently deploying.

21

Download Path: https://spsd.codeplex.com/

SharePoint Diagnostic Studio 2010

Microsoft SharePoint Diagnostic Studio 2010 (SPDiag version 3.0) was created to simplify and standardize troubleshooting of Microsoft SharePoint 2010 Products, and to provide a unified view of collected data.

This tool can be used for-

  • Gathering relevant information from a farm
  • Displaying the results in a meaningful way
  • Identifying performance issues
  • Sharing or exporting the collected data
  • Providing reports for analysis

And much more…

22

Download Path: https://technet.microsoft.com/en-us/library/hh144782(v=office.14).aspx

SPServices

SPServices is a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.

23

Download Path: http://spservices.codeplex.com/

SharePoint LogViewer

SharePoint Log Viewer is a Windows application for reading and filtering Microsoft SharePoint ULS Logs.

It offers the following key features-

  • View multiple SharePoint log files at once
  • Search by any field
  • Filter the log by any field
  • File drag & drop support
  • Live monitoring for entire farm
  • Export filtered log entries
  • Bookmark log entries
  • Get popup notification of SharePoint log events from system tray
  • Receive email notifications on errors
  • Redirect log entries to event log
  • Supports SharePoint 2007, 2010 and 2013

24

Download Path: http://sharepointlogviewer.codeplex.com/

FxCop

FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements. Many of the issues concern violations of the programming and design rules set forth in the Design Guidelines, which are the Microsoft guidelines for writing robust and easily maintainable code by using the .NET Framework.

25

Download Path: https://msdn.microsoft.com/en-us/library/bb429476(v=vs.80).aspx

JavaScript Beautifier

This online tool is used to beautify, unpack or De-obfuscate JavaScript and HTML, make JSON/JSONP readable, etc.

26

Download Path: http://jsbeautifier.org/

JSON Formatter & Validator

This is an online tool to that can be used to validate the JSON Packets

27

28

Download Path: https://jsonformatter.curiousconcept.com/

Being a SharePoint Developer I can say using these tools should be the second habit for SharePoint Developers to enhance their development capabilities which results in quick delivery turn around.

Hope you all find it helpful.

SharePoint 2010 References

SharePoint 2010 Installation

  1. Managing and Implementing Microsoft SharePoint 2010 Projects
  2. Practical SharePoint 2010 Information Architecture

SharePoint 2010 Architecture & Governance

  1. Pro SharePoint 2010 Disaster Recovery and High Availability
  2. Pro SharePoint 2010 Governance

SharePoint 2010 Project Management

  1. SharePoint 2010 for Project Management, 2nd Edition
  2. Pro Project Management with SharePoint 2010

SharePoint 2010 Development

  1. Using Microsoft InfoPath 2010 with Microsoft SharePoint 2010 Step by Step
  2. Professional SharePoint 2010 Development
  3. SharePoint 2010 Development with Silverlight
  4. SharePoint 2010 Web Parts in Action
  5. Beginning SharePoint 2010
  6. Microsoft SharePoint 2010 Enterprise Applications on Windows Phone 7
  7. Inside Microsoft SharePoint 2010
  8. Microsoft SharePoint Foundation 2010 Inside Out

SharePoint 2010 Designer

  1. Pro SharePoint Designer 2010
  2. Beginning SharePoint Designer 2010
  3. Microsoft SharePoint Designer 2010 Step by Step

SharePoint 2010 Cloud Based Solution

  1. Developing Microsoft SharePoint Applications Using Windows Azure
  2. Professional SharePoint 2010 Cloud-Based Solutions
  3. Pro SharePoint 2010 Development for Office 365

SharePoint 2010 Search

  1. Pro SharePoint 2010 Search
  2. Working with Microsoft FAST Search Server 2010 for SharePoint

SharePoint 2010 PowerShell

  1. Microsoft SharePoint 2010 and Windows PowerShell 2.0

SharePoint Best Practices

  1. Expert SharePoint 2010 Practices

SharePoint 2010 Business Intelligence

  1. Professional Business Connectivity Services in SharePoint 2010
  2. Microsoft SharePoint 2010 Business Application Blueprints
  3. Microsoft SharePoint 2010 Business Intelligence Unleashed
  4. Microsoft SharePoint 2010 PerformancePoint Services Unleashed

SharePoint 2010 Branding

  1. Professional SharePoint 2010 Branding and User Interface Design
  2. Microsoft SharePoint 2010 Administration Cookbook

SharePoint 2010 Administration

  1. Pro SharePoint 2010 Administration
  2. SharePoint Server 2010 Administration 24 Hour Trainer

SharePoint 2010 Enterprise Content Management

  1. SharePoint Server 2010 Enterprise Content Management

SharePoint 2013 User Guides

  1. SharePoint 2010 at Work
  2. SharePoint 2010 Field Guide
  3. SharePoint 2010 Six-in-One
  4. SharePoint 2010 How-To
  5. Microsoft SharePoint Foundation 2010 Step by Step
  6. SharePoint 2010 All-in-One For Dummies
  7. Microsoft SharePoint Server 2010 Bible