Category Archives: Microsoft

Running high trust apps / plugins with Sharepoint Foundation 2013

The User Profile service is not available on Sharepoint Foundation and therefore high trust apps are not supported.   However I found that after installing a high trust app it worked until restarting IIS, and after that it would generate authentication errors.  Re-uploading the app package to the app site fixed the authentication errors and allowed the app to run properly again.

I could not find an API to automate this re-upload process, so instead it can be done using a headless browser.

Here’s an example in casperjs (note that on Windows casperjs must be installed in a path without spaces):


var url = 'https://yourdomain.com/sites/appcatalog/_layouts/15/start.aspx#/AppCatalog/Forms/AllItems.aspx'
var file = 'sharepoint-package.app'
var user = 'username'
var pass = 'password'

var casper = require('casper').create();

casper.start();
casper.setHttpAuth(user, pass);

casper.thenOpen(url, function() {
  this.echo(this.getTitle());
  this.waitForSelector('#idHomePageNewDocument-WPQ2', function() {
    this.echo("Found selector");
  });
});

casper.thenClick('#idHomePageNewDocument-WPQ2', function() {
  this.echo("Clicked button");
  this.waitForSelector('.ms-dlgFrameContainer > iframe', function() {
    this.echo("Got the iframe");
  });
});

casper.withFrame(1, function() {
  this.waitForSelector('#aspnetForm', function() {
    this.echo("Found form");
    this.fill('#aspnetForm', {
      'ctl00$PlaceHolderMain$ctl01$ctl04$InputFile': file,
    }, false);
    this.wait(3000, function() {
      this.click('#ctl00<em>PlaceHolderMain</em>ctl00<em>RptControls</em>btnOK');
      this.echo("Clicked button");
    });
  });
});

The term ‘Get-SPApplicationPrincipal’ is not recognized as the name of a cmdlet, function, script file or operable program.

Ignore what it says on this technet page: http://technet.microsoft.com/en-gb/library/jj219714(v=office.15).aspx

The command is actually Get-SPAppPrincipal.

You can see the correct command here: http://technet.microsoft.com/en-us/library/jj219664(v=office.15).aspx

 

 

Windows console encoding

Filenames on NTFS are encoded in UTF-16.  The windows console is set by default to some other encoding entirely.  This makes working with files with ‘special’ characters in the filenames impossible…

In my case, I was using the following common code to delete files and folders in a directory:

set folder=”C:\test”

cd /d %folder%

for /F “delims=” %%i in (‘dir /b’) do (rmdir “%%i” /s/q || del “%%i” /s/q)

 

But files with certain unicode characters were not being deleted.  To fix this, add the following at the top of the file:

chcp 10000

 

This changes the encoding to UTF-16.

Or if you’re using cmd and the dir command, change the font first to Lucida Console (as the default font has a very limited character set).

Sharepoint 2013 Provider-Hosted App Architecture Notes

Trying to build a Sharepoint 2013 app has probably been the worst experience of my coding life so far.

The Microsoft docs make it sound so easy; there are so many ways you can build an app!  You can use any programming language you like!  Look, we have a REST interface!  Look, mobile app APIs!

Hey awesome,  you think, looking through the initial introductory documentation, yeh all the different information is a bit confusing, but look, they have how tos and the APIs are documented properly, how hard could it be?

Well, after wasting A LOT of time following guides and trying to build solutions that work, here’s some information that happened to be crucial to the architectural decision making of the apps that I didn’t come across until much too late.  Probably it’s wrong, because I’m finding it extremely difficult to get actual facts about the different ways you can build sharepoint apps, despite the millions of confusing articles on the Microsoft site (none of which seem to contain all the information you need to know), and lots of tutorials (written only by people coding in ASP hosting their sites on Azure or using OAuth).

 

Provider-hosted apps using the REST API:

  • You can either use the javascript cross-domain library or use OAuth
  • Using OAuth requires an account with Azure AD and you also need to configure your Sharepoint installation to use Azure AD (and obviously the Sharepoint installation needs access through firewalls etc to communicate to Azure AD).  In addition, the app needs to be registered in Azure.
  • I’ve seen some tutorials that say for testing you just need to register the app in SP and not Azure, and that you don’t need the Azure AD in this case; I couldn’t get this to work.

Provider-hosted apps using high trust:

  • The how-to guides all use a couple of Microsoft provided C# files for the authentication, in addition to Windows Authentication for the site in IIS, and I can’t see any documentation on how the process actually works.  Reading through the files, they get the Windows user information, so I have a feeling this method can only be used for apps built (1) in ASP/C# running on a windows machine, and (2) in the same domain as the sharepoint installation.

 

So if you want to build an app that can modify sharepoint data in any non-Microsoft language, and host it on a non-Windows machine, and don’t want to pay for an Azure subscription, and don’t want to change the authentication method of your sharepoint site, your options are:

  1. Javascript frontend to deal with Sharepoint, plus likely a backend of whatever to do anything you can’t with javascript (use 3rd party APIs etc)
  2. A high trust app to act as a proxy between your app and the sharepoint installation*

*I’m still trying to figure out how it would be possible to send the REST request I want to make to sharepoint to the proxy instead, and have that sign it and forward it on to sharepoint…

Using an OEM licence with a retail copy of Microsoft XP

The only OS I’ve done this with is XP Home, they have tools for Vista and Windows 7 so could possibly work for them as well.

Also, I was on the phone to a guy in Microsoft at the time; I assume anyone could do this, but there’s a slight chance that he did something to allow my key to convert.

In any case, the instructions are very simple:

1) Go to this page: http://windows.microsoft.com/en-US/windows/help/genuine/product-key and choose Windows XP tab at the top

2) Click on the link for the Windows Product Key Update Tool, and run it

3) Follow the installer, it should tell you it’s been successful when completed, and wants a restart

The Microsoft page says after activating you are required to activate Windows XP; I didn’t need to do this so not sure how accurate it is.

 

If anyone has tried the Windows Vista and Windows 7 versions (these say explicitly that they’re for using a, for example, Windows 7 Home licence with an installation of Windows 7 Ultimate, whereas the XP version doesn’t really say what it’s for, so I’m not sure if they have the same magical retail <> OEM conversion abilities – talking of which, I’m pretty sure this didn’t actually convert my licence to a retail copy, just forced my retail installation to accept my OEM key) let me know how it went.