Copy to SharePoint root from Sublime Text

Note, this is intended for your local development only, not a production environment!

At the moment I’m doing lots and lots of JavaScript for SharePoint, which means this:

  1. Write some JavaScript
  2. Use a Visual Studio plugin to copy to SharePoint root (usually Fishbone’s tool)
  3. Reload page (and by that I mean wait for a long, long time for the page to reload)

I’m doing my development in a virtual machine, with limited resources and Visual Studio seems to be hogging most of them, leaving next to nothing to the SharePoint server.

And I also like working in Sublime Text, I’m just so much more proficient in it.

Solution: Do it all i Sublime!

Here’s what we did: A shortcut to copying a file to the SharePoint hive using the Sublime build system.

1. Create a Sublime build file

In Sublime, go to Tools –> Build System –> New Build System

This creates you a file that looks like this:

Save that, name it to what you want your build system to be called (.sublime-bild as file ending). In it we will call on a powershell script. I saved it in the default location:

 

2. Creating a Powershell script to copy the file

Powershell will simply just do a Copy-Item. The file that you build with our custom build system will be copied from its current location to the hive. It looks like this:

This script takes one parameter: the location of the file that you are calling ”build” on. In order to put it in the correct location in the hive, it checks the folder hierarchy relative to the ”Layouts”-folder. This means that you have to have the file you’re working on in a path that contains a folder named ”Layouts”.

For example, my JavaScript file is located here:

This means that it will end up in the SharePoint hive here:

Save the script somewhere, and name it CopyToSharePointRoot.ps1

3. Using the Powershell script from the build file

We will now change the build-file to make it use the Powershell script with the correct parameter. Change the file you created in the first step to look like this:

In this, change ”exact-location-to-your-ps1-script” to the location of your CopyToSharePointRoot.ps1-file. Remember to have double \ for folders. The $file in the last row is a magic parameter given to the build file by Sublime, which we pass on to our script.

4. Using the build system

Got to Tools – Build –> Choose your new build system

If it’s not there, go back to step one and make sure you have the correct location and file ending.

Now open your file that you wish to copy to the hive, change it, hit save and the ctr + b. This should execute the script, and something like this should come up in your Sublime terminal:

 5. Wow, this would be so awesome as a Sublime package!

Fear not, we’re on it!

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *