SharePoint has lots of development techniques. And, they keep growing. By the time I am finished writing this article Microsoft might come up with another. So, let’s go through various options for SharePoint custom development and explain when to and when not to use them…

Before we start, let’s talk about the various ways to deploy SharePoint:

  • On-Premises: on-premises is when you install a SharePoint server and control the Infrastructure. You have more options from a SharePoint Development technique perspective with on-premises implementations. However, you have the headache of maintenance and upgrades.
  • SharePoint Online: we are talking about the Office 365 cloud here. Microsoft maintains the servers for you. Microsoft does incremental upgrades. But, because you don’t control the servers, you have limited SharePoint Development techniques. Why? Microsoft doesn’t want you breaking a server that is shared with you and someone else.
  • Classic vs. Modern pages: this is an option if you use SharePoint Online (note: Microsoft has this on the roadmap for SharePoint 2019 On-Premises). As of right now, Modern pages are evolving and some of the techniques we will talk about differ for Modern pages vs. Classic pages.

Farm Solutions

SharePoint Farm solutions are the “old-school” way to develop against SharePoint. As any SharePoint developer who’s been around since the SharePoint 2010 version – they’ve probably done a farm solution. This is .Net development and server-side deployment. Basically, a developer assembles a deployable package of code. Typically the code is organized using the concept of site features which allow SharePoint admins to toggle the deployed code. These packages also have XML based configurations that allow developers to define the scope, type (ex: Custom Action vs Style Sheet), storage options (such as pushing files to places in SharePoint like the Master Page Gallery), etc.

The main point about Farm solutions is that it is a mix of putting files on the actual SharePoint server in a place called the “hive” and registering those files within the SharePoint database. The key here is that files are actually placed on the server. And server-side code runs against dlls on the SharePoint server.

The main benefit of Farm solutions is that you have full access to the SharePoint server-side API. You also have a variety of techniques that can only be used by leveraging server-side code (note: SharePoint client-side APIs are catching up to the server-side APIs, but anyone that’s developed long enough knows there are just some things you need to do on the server).

The main downside of Farm solutions is that you have to deploy them to the server. What does that mean? It means these only work for On-Premises installations. That’s right, the way we’ve developed SharePoint for over 10 years’ is no longer an option for SharePoint Online.

Another downside of Farm solutions is that you have to develop on a SharePoint server. Most SharePoint developers actually have virtual SharePoint machines purely to do development. If you don’t develop on a SharePoint server Visual Studio will complain about missing dlls required to do development. There are some “tricks” to develop on your own machine, but they all have side-affects. So, the investment and maintenance to develop Farm Solutions is very high.

When to use Farm Solutions:

Only use Farm Solutions for On-Premises installations. In fact, this should be a last resort. Why? There is always the chance you will migrate to SharePoint Online in the future. You could spend weeks, months, if not  years building something that you might have to completely re-build in the future. I rarely build Farm Solutions anymore. I’ve converted too many of these to SharePoint Online recently. So, with all new implementations, I am forward thinking and try to never resort to this development technique anymore.

Sandboxed Solutions

Sandboxed Solutions were introduced in SharePoint 2010. They use a limited server-side API and run in something called the Sandbox. The intent from Microsoft when introducing Sandboxed Solutions was a valid attempt. They were trying to be forward thinking for co-hosted SharePoint servers and probably eventually for their cloud based solutions. Supposedly, Sandboxed Solution code was limited in order to prohibit developers from writing code that could greatly affect the security or stability of a SharePoint environment. However, many developers didn’t like the limitations of Sandboxed Solutions. Over time Microsoft started taking features away from Sandboxed Solutions. In fact, Microsoft no longer allows custom code in Sandboxed Solutions. So, basically Sandboxed Solutions have been relegated to deployment of declarative (anything configured through XML – copying files, list template instances, etc…) and client-side customizations.

There are still some advantages of being able to do declarative deployments to SharePoint. You can deploy pages, master pages, styles, JavaScript and more this way. If you are purely looking to package up files and deploy to a SharePoint environment, this is still a valid technique.

In addition, Sandboxed Solutions run On-Premises and SharePoint Online.

However, there are downsides. Similar to Farm Solutions, you need a SharePoint server to do development. If you try to add a Sandboxed Solution project to Visual Studio on your local development machine you will get an error. It’s the same problem as Farm Solutions. It’s looking for dlls on your computer that come with the SharePoint installation.

In addition, what you can actually do with Sandboxed Solutions is very limited. You can’t build complicated WebParts. You can’t write code that accesses the SharePoint server-side API. There is just a lot you can’t do.

When to use Sandboxed Solutions:

The use cases are becoming rare. But, I’ve seen some interesting use of Sandboxed Solutions from branding companies. One of our partners, BindTuning, pushes out their files this way. How can they do this? Easy – they are a branding company. They are pushing out Master Pages, List Instances and JavaScript. Even their Web Parts are all client code (i.e.: JavaScript). However, they aren’t building complicated applications and deploying with this technique. That would be difficult. They are purely pushing files to your SharePoint site collection.

Interesting note on deploying WebParts with this technique: I was really curious about the BindTuning Web Parts. They have custom Web Parts with custom properties. I didn’t think that was possible with all the restrictions on Sandboxed Solutions. So, I looked into their Web Part properties. They actually built their own property editor (i.e.: they don’t use the Web Part Property toolpane like we are used to). They have a slick custom UI for their Web Part properties. Then they actually store the properties in the HTML. That way, when their client side code runs, it first just reads the properties. So, basically their Web Parts are Script Editors (or Content Editors) with embedded HTML and JavaScript. Pretty slick implementation if you ask me.

 

Add-Ins

Add-Ins (previously known as Apps) were introduced in SharePoint 2013. RePoint is very familiar with them. In fact, we won the inaugural Office/SharePoint Add-In development contest. Basically, Microsoft was trying to solve a couple issues with one development technique.

  1. Ability to run in SharePoint Online
  2. Ability to deploy to the Microsoft Office Store to sell
  3. Similar techniques for all Office products (i.e.: similar techniques in SharePoint, Word, PowerPoint, Excel and Outlook)

The basic premise of Add-Ins is that they run in a separate context than the actual SharePoint site (i.e.: they are actually running in a separate website). You connect the add-in website to the SharePoint site through oAuth and use the client-side framework to talk to each other.

Imagine this scenario: You want to build a custom website, but would like to store data in SharePoint and use SharePoint to authenticate. This is a perfect scenario for Add-Ins. In fact, RePoint Technologies built our timesheet system this way. We built a custom website and made it a SharePoint Add-In. We log in through SharePoint to get to this custom website. And, this custom website stores data in SharePoint lists so we can take advantage of SharePoint workflows.

There are technically 2 types of Add-Ins for SharePoint:

  1. Provider Hosted – this means the Add-In website lives outside of SharePoint. For instance: you could host the site in Azure, Amazon Cloud, local servers, etc… SharePoint connects to this website through the oAuth techniques and allows the Add-In website to talk to SharePoint. The benefit of this is you can actually write server-side code on your server. You still have to use the client-side APIs to communicate with SharePoint. But, if you have a requirement to do server-side code, you can use the server to run it.
  2. SharePoint Hosted – this means the Add-In website actually lives within SharePoint. Technically, SharePoint creates a custom site collection for you to host the Add-In. The upside to this is that you don’t have to setup separate servers to host the website. The downside to this is you can only write client-side code. No server-side code is allowed with this technique.

In addition, there are a couple options when building the Add-In. One important one is called the App Part. This was “supposed” to be the way you write Web Parts when the Add-In model was introduced. It allows you to deploy an Add-In to the Web Part gallery so end users can add it to their page. In addition, it lets you build Web Part properties so end users can configure. At first glance, it looks like a great technique if you want a custom Web Part. But, if you look behind the scenes, it is just an iFrame. That’s right – since Add-Ins run in a separate site it has to show that separate site like it is part of the page. How do you do that? You use an iFrame. I hate iFrames. Why:

  1. Setting Width and Height is difficult – luckily SharePoint put a hook into this that allows us to programmatically set the width and height of the iFrame from the code in the Add-In. However, that doesn’t work all the time. Let’s say you are building an Accordion that changes heights dynamically. It’s not going to look smooth if you have to change the height programmatically after it finishes expanding. Basically, you have to really think through this issue if you want to use Add-Ins for App Parts.
  2. Performance – you are loading another webpage within your page. It takes time to load. Users are going to see it loading. There is no way around this. It will slow the overall load time of your page down.
  3. Deployment – The typical model for deploying an Add-In is to go to the App Catalog of your SharePoint instance and deploy the code. Then you go to the various sites in SharePoint and activate it (similar to a feature). This is really nice if you are deploying an “option” (i.e.: each owner of a site has an option to get the Add-In). But, what if you want to push out a global deployment of the Add-In (for instance: you want to globally push out the App Parts to an entire Intranet). You can’t do it! Add-Ins do have an option when you are building and deploying them to deploy globally. But, guess what – it won’t do it for the App Parts. That’s right, it’s even in the Microsoft documentation. That is one of the limitations. So, the only option is to manually activate the feature on all the sites and/or write a Powershell to do it. Also, you have to do this for any update (such as adding new parameters). It’s a pain.

When to use Add-Ins:

  1. You have a completely separate website you want to build with your own techniques and just need SharePoint for authentication, storage and other techniques that you can call to through the client-side API.
  2. You want to sell something on the Microsoft Office store as a third party
  3. You need to build a custom Web Part with properties and you have the following situation:
    1. SharePoint Online – so you can’t build a Farm Solution
    2. Can’t build a Sandboxed Solution because you don’t have the environment
    3. Can’t build a Sandboxed Solution because you need configurable parameters to the Web Part and don’t have the time to design your own, custom way to save properties
    4. Have a requirement that the Web Part must be reusable and must have properties. Otherwise we could use a simple Script Editor.

Script Editor:

Even though this section is titled “Script Editor”, the same techniques can be used with the Content Editor Web Part. The idea is to write HTML and JavaScript directly on your page. The Script Editor is newer and I like it better. But, you can do it through the Content Editor also.

This is my go to technique when I have a single component to put on a page. I just drop a Script Editor on the page and write my HTML and JavaScript. Easy as that. Solves most of my requirements on a daily basis.

But, there is no way to package this up and deploy it.

Note: It is semi-possible to package up a Script Editor. You can actually write an Add-In purely to deploy Script Editor code. In fact, the Microsoft Patterns and Practices team have a whole article on how to do that. But, even if you do that, it doesn’t have any properties. So, there is no way to put custom properties on it.

In addition, there is no Script editor for “Modern” SharePoint sites. However, some people in the community have built third party script editors using the SPFx framework. But, Microsoft doesn’t have one. It’s almost like they don’t want us to write simple JavaScript on the page. Microsoft seems to be doing everything in their power to stop us from doing it. Why?

This is a real downfall of Microsoft’s new direction with SharePoint. They are pushing SharePoint more and more towards making it really hard to develop the simple stuff. They have some great new frameworks like SPFx (which we will talk about next). However, that takes developers, setup and time just to get working. It’s meant for really complicated stuff. But, most of the time our requirements are simple. In fact, there is a whole push for something called the “citizen developer”. This is someone who can develop (particularly client-side code), but isn’t a true developer in the sense they can work like Microsoft is pushing us to lately. Basically, Microsoft is actually trying to (or at least it seems that way) make it hard to do this type of stuff. I get why. They are trying to bring integrity to SharePoint. They don’t want someone that doesn’t know what they are doing to add a Script Editor to a page, write bad JavaScript and then it looks like SharePoint doesn’t work. So, they take away our ability to do this easy. What do I mean about doing this easy? In my opinion, if Microsoft added a Script Editor with property mapping ability, we could cover 75% of all requirements and we could create a deployment package for it easily. That should be there. There is no reason it is not.

When to use Script Editor:

Use when you want to write a single, non-reusable, component on a page. Great for a non-reusable Web Part. Something you want to write once for a requirement on a single page.

 

SPFx:

The SharePoint Framework (SPFx) is the newest way to build SharePoint Web Parts. This was built particularly for the Modern SharePoint site. It’s actually great. Developers can build client-side components that are packagable and can be deployed to a SharePoint site, just like classic Farm Web Parts use to be, or how SharePoint Add-Ins were supposed to work. In addition, Microsoft put a lot into the tooling around creating SPFx components. Microsoft is really pushing modern client-side development techniques like React and other modern frameworks. SPFx components can use all the client-side APIs to access SharePoint data. And, most importantly, SPFx runs in the current context and does not use iFrames! Thus, all the iFrame issues of SharePoint Add-Ins are gone.

SPFx components will work on the new modern SharePoint pages as well as classic pages. Basically, they are perfect for developing enterprise-wide, complex, custom Web Parts.

But, there is a catch – it’s difficult to do. The techniques used are very modern. Lots of command lines to setup projects. Using Gulp, Grunt, etc… It pushes newer client-side frameworks like React and Angular. Basically, all the stuff I love. However, not all developers are there yet. You really need to assess your development team before going down this path. I am finding that my clients are not setup to support this development. Most of my clients have .Net developers that maintain their environments. It’s hard to convince them to use this technique based on their skillsets.

When to use SPFx:

Use SPFx for all new Web Part development if you have a team that can support this modern type of client-side coding.

 

Soapbox:

Now it’s time for me to get on my soapbox. Add-Ins are horrible for Web Parts. Avoid the AppPart if you can. However, they are great for custom websites that just need to link to SharePoint. SPFx is great! But, meant for serious developers. Script Editor is my go to for small projects. However, it has limited re-usability. Basically, there are situations where we are stuck now-a-day when doing SharePoint Online development. With the new SPFx framework, Microsoft has put us into a box that only supports enterprise development strategies for simple updates. But, sometimes I just want to write simple JavaScript. Please Microsoft – give us a Script Editor with the ability to Map properties! Understand the “citizen developer” does exist. They need to write code too. Don’t confine your frameworks to enterprise Development strategies only. Think about small business and plan your roadmap appropriately.