Author Archives: Jani

Install First Approach Explained

I have worked with SharePoint since 2005 and I have seen quite many ways of building SharePoint solutions.

Now when more and more companies are using cloud based services it’s time to make small change to development also. If you have followed at least a little bit of SharePoint scene during last few years, you have heard Microsoft talking about SharePoint Online and Apps model (currently Add-Ins, perhaps they will change that again to something new). At first it was how to build Apps with User Interface and how all developers should start building AppParts instead of WebParts. It has been now little less that three years since Richard diZerega posted an article about an app that will create new site collections to SharePoint (http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2013/04/04/self-service-site-provisioning-using-apps-for-sharepoint-2013.aspx) using Client Side Object Model (CSOM). Now we can benefit from the work done by pioneers. OfficeDevPnp and OfficeDevPnp-PowerShell provide us excellent base to build on. Thank you for all who has made this possible.

Creating the first project

We will create two projects (PowerShell and Web Application) inside one solution. The idea behind this is

To be able to deploy from the first second of the project.
To be able to configure each environment identical.

Why this is important? It’s important because we are building application in development environment. Then we need to deploy same code and configurations to test environment and after acceptance test we will deploy everything to production environment. We can (re)create out development or test environment whenever we want with one script even development environment would be our O365 development tenancy.

Start Visual Studio and select PowerShell | PowerShell Script Project.
Name: MyProject.SharePointApp1.Scripts
Solution name: MyProject.SharePointApp1
Delete Script1.ps1 file.

Add New ASP.Net Web Application to the Solution.
Name: MyProject.SharePointApp1.Web
Select Empty Template
Clear selection from Host in the cloud.
After you have created a project add new folder called Content.

After you have completed all tasks your solution should be similar to this.

Add New PowerShell Script Item ‘CreateSiteCollection.ps1’ to Scripts project. You can see list of time zone id’s and web templates from my previous posts. Execute script. It will create default team site that we can use as playground for next projects.

#
# CreateSiteCollection.ps1
#
Connect-SPOnline -Url “https://tenant-admin.sharepoint.com” -UseWebLogin
New-SPOTenantSite -Title App1 -Url https://tenant.sharepoint.com/sites/app1 -Owner “admin@tenant.onmicrosoft.com” -TimeZone 59 -Lcid 1053 -Template “STS#1” -RemoveDeletedSite

Now when we can create site, we also need to delete sites when we want to erase all old configurations. Therefore, we need to create new PowerShell Script Item ‘DeleteSiteCollection.ps1’.

#
# DeleteSiteCollection.ps1
#
Connect-SPOnline -Url “https://tenant-admin.sharepoint.com” -UseWebLogin
Remove-SPOTenantSite -Url https://tenant.sharepoint.com/sites/app1 -SkipRecycleBin

Adding jQuery

We will continue working with our App1 project by adding jQuery NuGet package to Web project.

  1. Selecting Web project from Solution Explorer
  2. Select Manage NuGet Packages from context menu.
  3. Change tab to Browse
  4. Use search to find jQuery and install it.

Creating the first script

Now we have added jQuery to our project. It’s time for simple hello world demo. Create new JavaScript file ‘project.js’ to Scripts folder inside Web project.

jQuery(document).ready(function () {
alert(“Hello World!”);
});

Updating files to SharePoint

After we have installed jQuery and created project.js file we need to create new PowerShell Script ‘UpdateFiles.ps1’. We will upload jQuery with our own script to the site.

#
# UpdateFiles.ps1
#
Connect-SPOnline -Url “https://tenant.sharepoint.com/sites/app1” -UseWebLogin
Add-SPOFolder -Folder “SiteAssets” -Name “Scripts” -ErrorAction:SilentlyContinue
Add-SPOFolder -Folder “SiteAssets/Scripts” -Name “jQuery” -ErrorAction:SilentlyContinue
Add-SPOFile -Path “C:\SourceCode\MyProject.SharePointApp1\MyProject.SharePointApp1.Web\Scripts\jquery-2.2.0.min.js” -Folder “SiteAssets/Scripts/jQuery”
Add-SPOFile -Path “C:\SourceCode\MyProject.SharePointApp1\MyProject.SharePointApp1.Web\Scripts\Project.js” -Folder “SiteAssets/Scripts”

Files have been uploaded there successfully as we can see from the following image, but the problem is that we didn’t get the message. We still need to add those scripts to the page so that we can execute them in user’s browser.

Adding scripts to the site

Adding custom scripts to site can be done using Add-SPOCustomAction. The problem is that you can’t define script source even it has parameter called Url. At first we need to create custom action and then we need to update ScriptSrc property. Now you can see “Hello World!” text on you site.

#
# ActivateScripts.ps1
#
Connect-SPOnline -Url “https://tenant.sharepoint.com/sites/app1” -UseWebLogin
Add-SPOCustomAction -Description “jQuery” -Location “ScriptLink” -Name “jQuery” -Title “jQuery” -Group “Project” -Sequence 10050 -Scope “Site”
$action = Get-SPOCustomAction -Scope “Site” | ? { $_.Description -eq “jQuery” }
$action.ScriptSrc = “~sitecollection/SiteAssets/Scripts/jQuery/jquery-2.2.0.min.js”
$action.Update()
Execute-SPOQuery

Add-SPOCustomAction -Description “ProjectScript” -Location “ScriptLink” -Name “ProjectScript” -Title “ProjectScript” -Group “Project” -Sequence 10051 -Scope “Site”
$action = Get-SPOCustomAction -Scope “Site” | ? { $_.Description -eq “ProjectScript” }
$action.ScriptSrc = “~sitecollection/SiteAssets/Scripts/Project.js”
$action.Update()
Execute-SPOQuery

Now we have simple template that allows us to update scripts and sites with scripts. If we need to set up new environment, all we need to do is to execute those scripts and environment is ready for action.

SharePoint Development: How to start?

Introduction

There are two versions of SharePoint available:

  • SharePoint 2013 (SharePoint 2016 will available soon).
  • SharePoint Online (Hosted by Microsoft)

You can use either of those to develop SharePoint applications. There is one huge difference. Older SharePoint developers have used Solutions (specially Farm Solutions) to develop applications for SharePoint. This type of development is not an option in Online version of the SharePoint. Farm solutions have been developed using C# and they are packages that contain configurations for SharePoint and also DLL files containing executable code. Biggest problem in this model is that one poorly written application can bring whole server down and there are no way of isolating poorly behaving application.

Figure 1 Principle of Farm Solution

This is totally impossible scenario in cloud environment where single shared environment can host several companies in their isolated tenants. If one company could install poorly written application, it could make harm to several companies and that is not acceptable. To address this type of issues, Microsoft started designing new way of developing applications. This was called User Solutions.

Get you own tenant

Starting SharePoint development is really easy. All you need is own tenant from Office 365. There are several ways of getting your own playground:

  • If you have existing MSDN subscription, you can get Office 365 development tenant. This tenant is available for you as long as you have valid MSDN subscription.
  • If you don’t have MSDN, but you are an employee of the Microsoft partner, you can order demo tenant from Microsoft. This option has expiration date, so you can expect that Microsoft will close you tenant in the future.
    https://demos.microsoft.com/

  • If you don’t have any other mean, you can always order trial tenant from Microsoft. This option has expiration date, so you can expect that Microsoft will close you tenant in the future.
  • If you really want to be a “pro” you can buy your own tenant. This is ultimately the best option, because it allows you to use all Office365 features without limiting factors of previous options.

In any case, it doesn’t matter which option you choose, because we are going to script everything and you can always setup everything in place if you happen to lose your tenant.

Setting up your development environment

You need following tools to start developing SharePoint:

  • OfficeDevPnP.PowerShell Commands https://github.com/OfficeDev/PnP-PowerShell.
    This is set of PowerShell commands that will utilize SharePoint Client Side Object Model (CSOM) and can be used with SharePoint Online. This is huge help for every developer who is working with SharePoint, because it allows you to automate your installation and configuration tasks.
  • Visual Studio https://www.visualstudio.com/vs-2015-product-editions
    Remember to select both Office and Web Developer Tools. Both options are required for proper SharePoint development.

Configuring Visual Studio

Start Visual Studio and install PowerShell Tools for Visual Studio 2015.
Tools | Extensions and Updates.
Select Online and type powershell to search box.
This will require Visual Studio restart.

Now we have configured Visual Studio ready for SharePoint development.

SharePoint Online Templates

Here is a list of SharePoint Online web templates. These are needed if you want to create a new site collection.

#
# ListWebTemplates.ps1
#
Connect-SPOnline -Url “https://tenant-admin.sharepoint.com” -UseWebLogin
Get-SPOWebTemplates -Lcid 1033
Name Title Category Compatiblity Level
STS#0 Team Site Collaboration 15
BLOG#0 Blog Collaboration 15
BDR#0 Document Center Enterprise 15
DEV#0 Developer Site Collaboration 15
OFFILE#1 Records Center Enterprise 15
EHS#1 Team Site – SharePoint Online configuration Enterprise 15
BICenterSite#0 Business Intelligence Center Enterprise 15
SRCHCEN#0 Enterprise Search Center Enterprise 15
BLANKINTERNETCONTAINER#0 Publishing Portal Publishing 15
ENTERWIKI#0 Enterprise Wiki Publishing 15
PROJECTSITE#0 Project Site Collaboration 15
PRODUCTCATALOG#0 Product Catalog Publishing 15
COMMUNITY#0 Community Site Collaboration 15
COMMUNITYPORTAL#0 Community Portal Enterprise 15
SRCHCENTERLITE#0 Basic Search Center Enterprise 15
visprus#0 Visio Process Repository Enterprise 15

SharePoint Time Zones

Here is a list of SharePoint Online time zone id’s. These are needed if you want to create a new site collection.

#
# ListTimeZones.ps1
#
Connect-SPOnline -Url “https://tenant.sharepoint.com” -UseWebLogin
Get-SPOTimeZoneId
Id Description Identifier
0 None No:ne
2 GREENWICH MEAN TIME DUBLIN EDINBURGH LISBON LONDON UTC
3 BRUSSELS COPENHAGEN MADRID PARIS UTC+01:00
4 AMSTERDAM BERLIN BERN ROME STOCKHOLM VIENNA UTC+01:00
5 ATHENS BUCHAREST ISTANBUL UTC+02:00
6 BELGRADE BRATISLAVA BUDAPEST LJUBLJANA PRAGUE UTC+01:00
7 MINSK UTC+02:00
8 BRASILIA UTC-03:00
9 ATLANTIC TIME CANADA UTC-04:00
10 EASTERN TIME US AND CANADA UTC-05:00
11 CENTRAL TIME US AND CANADA UTC-06:00
12 MOUNTAIN TIME US AND CANADA UTC-07:00
13 PACIFIC TIME US AND CANADA UTC-08:00
14 ALASKA UTC-09:00
15 HAWAII UTC-10:00
16 MIDWAY ISLAND SAMOA UTC-11:00
17 AUKLAND WELLINGTON UTC+12:00
18 BRISBANE UTC+10:00
19 ADELAIDE UTC+09:30
20 OSAKA SAPPORO TOKYO UTC+09:00
21 KUALA LUMPUR SINGAPORE UTC+08:00
22 BANGKOK HANOI JAKARTA UTC+07:00
23 CHENNAI KOLKATA MUMBAI NEW DELHI UTC+05:30
24 ABU DHABI MUSCAT UTC+04:00
25 TEHRAN UTC+03:30
26 BAGHDAD UTC+03:00
27 JERUSALEM UTC+02:00
28 NEWFOUNDLAND AND LABRADOR UTC-03:30
29 AZORES UTC-01:00
30 MID ATLANTIC UTC-02:00
31 MONROVIA UTC
32 CAYENNE UTC-03:00
33 GEORGETOWN LA PAZ SAN JUAN UTC-04:00
34 INDIANA EAST UTC-05:00
35 BOGOTA LIMA QUITO UTC-05:00
36 SASKATCHEWAN UTC-06:00
37 GUADALAJARA MEXICO CITY MONTERREY UTC-06:00
38 ARIZONA UTC-07:00
39 INTERNATIONAL DATE LINE WEST UTC-12:00
40 FIJI ISLANDS MARSHALL ISLANDS UTC+12:00
41 MADAGAN SOLOMON ISLANDS NEW CALENDONIA UTC+11:00
42 HOBART UTC+10:00
43 GUAM PORT MORESBY UTC+10:00
44 DARWIN UTC+09:30
45 BEIJING CHONGQING HONG KONG SAR URUMQI UTC+08:00
46 NOVOSIBIRSK UTC+06:00
47 TASHKENT UTC+05:00
48 KABUL UTC+04:30
49 CAIRO UTC+02:00
50 HARARE PRETORIA UTC+02:00
51 MOSCOW STPETERSBURG VOLGOGRAD UTC+03:00
53 CAPE VERDE ISLANDS UTC-01:00
54 BAKU UTC+04:00
55 CENTRAL AMERICA UTC-06:00
56 NAIROBI UTC+03:00
57 SARAJEVO SKOPJE WARSAW ZAGREB UTC+01:00
58 EKATERINBURG UTC+05:00
59 HELSINKI KYIV RIGA SOFIA TALLINN VILNIUS UTC+02:00
60 GREENLAND UTC-03:00
61 YANGON RANGOON UTC+06:30
62 KATHMANDU UTC+05:45
63 IRKUTSK UTC+08:00
64 KRASNOYARSK UTC+07:00
65 SANTIAGO UTC-04:00
66 SRI JAYAWARDENEPURA UTC+05:30
67 NUKU ALOFA UTC+13:00
68 VLADIVOSTOK UTC+10:00
69 WEST CENTRAL AFRICA UTC+01:00
70 YAKUTSK UTC+09:00
71 ASTANA DHAKA UTC+06:00
72 SEOUL UTC+09:00
73 PERTH UTC+08:00
74 KUWAIT RIYADH UTC+03:00
75 TAIPEI UTC+08:00
76 CANBERRA MELBOURNE SYDNEY UTC+10:00
77 CHIHUAHUA LA PAZ MAZATLAN UTC-07:00
78 TIJUANA BAJA CALFORNIA UTC-08:00
79 AMMAN UTC+02:00
80 BEIRUT UTC+02:00
81 MANAUS UTC-04:00
82 TBILISI UTC+04:00
83 WINDHOEK UTC+02:00
84 YEREVAN UTC+04:00
85 BUENOS AIRES UTC-03:00
86 CASABLANCA UTC
87 ISLAMABAD KARACHI UTC+05:00
88 CARACAS UTC-04:30
89 PORT LOUIS UTC+04:00
90 MONTEVIDEO UTC-03:00
91 ASUNCION UTC-04:00
92 PETROPAVLOVSK KACHATSKY UTC+12:00
93 COORDINATED UNIVERSAL TIME UTC
94 ULAANBAATAR UTC-08:00