SharePointRoot


Leave a comment

Simple AngularJS – getting started

With the buzz around AngularJS, I’ve kinda missed the boat on some of it – and getting started ‘late’.  

Then again, I’m a ‘fashionably late’ kinda person – and that’s A-OK with me !

🙂

In order to get started, I thought I’d share some observations and ideas.

YES – it’s a big topic – and this first post is a ‘hello world’ style mini-app.   

To get it working, just save the content to a separate file – one for the HTML and one for the JavaScript (app.js).

(1) The HTML

The following HTML is as basic as you can get – explanation below.

<!DOCTYPE html>
<html ng-app=”testApp”>
<body ng-controller=”testCtrl”>
    <script type=”text/javascript” src=”
http://code.angularjs.org/1.2.0rc1/angular.min.js”></script>
    <script type=”text/javascript” src=”app.js”></script>
    <h3>{{ greeting }}</h3>
</body>
</html>

The main pieces are highlighted :

  • testApp is the name of the ‘program’ like and is a container holder, for the whole page
  • testCtrl is the name of the ‘controller’ which is the portion of the app, and used for the model/controller execution.

You’ll note that these have special Angular attributes >  ng-app and ng-controller.

There are also a few JavaScript references – for the AngularJS code (include) – and our code (app.js).

(2) The JavaScript

Again, to keep it simple, this is pretty much the only bits you need.

var app = angular.module(‘testApp‘, []);

app.controller(‘testCtrl‘, [‘$scope‘, function ($scope) {
    $scope.messageText = “Hello friends !”;
}]);

This does the following logic :

  • Get a reference to the ‘program’ – ie. testApp – into a variable called ‘app’.
  • Use the ‘app’ variable and define the ‘controller’ – ie. testCtrl
  • Define a function to set the property (element) of ‘greeting’.

The key piece here is the thing called “$scope”.   This is a variable passed into the function – and thus you can do >  $scope.messageText.

This is because the value in HTML has {{braces}} around it.

Hope that’s enough to get a quick 101 jump start – the journey of a thousand miles begins with a single step…!

=============

Here’s a cool sample that builds upon the above – with more fields :

http://blogs.msmvps.com/deborahk/angularjs-101-ways-to-create-a-controller-actually-8/


Leave a comment

SQL Azure Admin Password

When creating a brand-new SQL Azure Database, I was unsure on how to connect to it.

There is a button to “Show connection strings” – but that shows as :

image

Thee is the ability to open within Visual Studio (bottom row of buttons) – but it would then ask me to provide a password – but HOW/WHAT is it !!??!

image

It turns out that there is an easy way to do this.

If you consider that each DATABASE will live on a specific SERVER, you need to set the Administrator password for the ‘SERVER’ itself.

  • Click on the link for the ‘server’

image

  • Flip to the ‘Dashboard’ tab
  • There’s a link to ‘Reset Admin Password’

image

Obviously – you don’t want to do this for EVERY database – but if you’re doing it for the first time, then you need to SET the password.

P.S.  The default login account is :   AzureCloudAdmin

Too easy – in the end !


Leave a comment

Invalid issuer or signature

I’ve been deploying a SharePoint app to a new farm (actually, it’s a different O365 tenant), and so I had to generate a new CLIENT ID and SECRET.

I’d updated this within the WEB.CONFIG of my provider hosted app – ASP.NET MVC running on Azure – and then published to my Azure WebSite.

BUT – I’m getting this error when using the app from SharePoint :

SecurityTokenException: Invalid issuer or signature.
image 

It turns out that I’d forgotten to update the properies within Azure.   

Those settings in the WEB.CONFIG are for a localhost deployment – you need to use the “CONFIGURE” page for Azure.

image

Scroll down – and check that you’ve correctly set the (NEW) client id and secret.

image

Make sure to click “SAVE” – and then you should be A-OK to simply re-try the SharePoint app.

It would be nice if the exception message gave more details !     “check the ClientID and Secret” !   

🙂

Hopefully that helps someone !


Leave a comment

The (very important) APP DOMAIN

SharePoint error : An error occurred while processing your request

I’ve just trying to get a Provider Hosted sample working – with a AZURE website – and an Office 365 App.   This has been an “all day” thing – not working !

I’d done all the steps – with the ClientId – and ClientSecret – and included in my WEB.CONFIG.

But – when accessing my App, I’d simply see a message :

An error occurred while processing your request

This is coming from the following code – within the ‘default.aspx’ for the website.

protected void Page_PreInit(object sender, EventArgs e)
{
    Uri redirectUrl;
    switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl))
    {
        case RedirectionStatus.Ok:
            return;
        case RedirectionStatus.ShouldRedirect:
            Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true);
            break;
        case RedirectionStatus.CanNotRedirect:
            Response.Write(“An error occurred while processing your request.“);
            Response.End();
            break;
    }
}

So – it was LOADING my site, but couldn’t display.

It turns out, that I’d been ‘faster-stepping’ through the wizard to assign the “CLIENT ID” and “CLIENT SECRET”.

If/when you’re using APPREGNEW.ASPX – make sure to put the correct Azure WebSite domain

As below – the APP DOMAIN is important – don’t just put ‘contoso’ or ‘localhost’.

image

It turns out, I’d been “super careful” on the CLIENT ID and CLIENT SECRET – but not paying much attention to the App-Domain.

Hope this helps – it woulda saved me a bunch-of-hours…!


1 Comment

SharePoint Search Results with DateTime field refiner

When configuring a SEARCH RESULTS page, you can include any of your own custom columns as ‘refiners’.   These show on the side of the results, allowing users to filter down the results.

When you choose a field as a refiner, the data shown will depend on the type of the field.      Eg.  TEXT fields, will just show as the item values

image

When using a DATE field – for some reason, there’s a nasty symptom that doesn’t show the values correctly !

This symptom was also highlighted and blogged by Simon Doy.

WHY ?    The field is showing as 2,012 and 2,013 ??

My refiner is doing the same thing – compared to the Out Of The Box Created field :

image

RESOLUTION

I’m happy to report that there’s a very simple fix – and it’s related to the NAME of the managed property you create.

In my example :

  • DON’T name the property as “STaRCreatedDateTime”
  • Instead – it should be “STaRCreatedDateTimeOWSDATE

There’s some SharePoint JavaScript code that looks for the ‘type’ of the field – within the tail of the field name.    Sure enough – it works !

image

Thanks to SIMON for the tips and investigation – his blog goes into a lot of depth, with a custom refiner to change the look/feel.

It was this tip that saved the day :

image

Thanks Eman !      (Credit where credit is due)

🙂


1 Comment

Show status image in SharePoint column

Recently, I was discussing a clever trick with a colleague, for showing HTML in a SharePoint column.  

For SP2003 and SP2007, you needed to include some additional JavaScript (TEXT2HTML / examples) – but with SharePoint 2010 + 2013, you can do it using a calculated column.

Source column : Priority

Firstly, we need to add a column that we’ll use at the ‘checker’ column – this might be something like a STATUS column, or % COMPLETE, or PRIORITY.

  • Create Column : Priority
  • Type : Number

image

Add some List Data

Just add a few items to the list – and pick some priorities.

image

You can do whatever VIEWS, or SORTING or GROUPING – whatever…!

Find some images

Use your favourite search engine to look up some status images – I found a cool set here (more instructions here) :

image

Save these images locally – and upload to your SharePoint site – eg. SiteAssets, or Style Library.  I’ve loaded mine into an “IMG” folder.

Eg.   /Style Library/IMG/red.png

Calculated column

We can now do the magic + fun bit.

  • Create a calculated column : Indicator
  • Type : Calculated
  • Formula :

=”<DIV><img src='” & IF(Priority=1, “/Style Library/IMG/red.png”, IF(Priority=2,”/Style Library/IMG/yellow.png”, IF(Priority=3,”/Style Library/IMG/green.png”, IF(Priority=4,”/Style Library/IMG/blue.png”)))) & “‘></DIV>”

This is essentially doing the following :

  • If Status = 1, put an IMG tag for RED
  • If Status = 2, put an IMG tag for YELLOW
  • etc

NB.  The way that the formula works is like EXCEL :

  • IF (condition, TRUE, FALSE)

This method (above) is nesting these :

  • IF (condition1, IMAGE, IF (condition2, IMAGE, IF (condition3, IMAGE, IMAGE ) ) )

Click back to your list to view your column :

image

What the !!?!    It’s just showing HTML !!

😦

The UberMagic Tip

You’d be thinking that this is a “dud” tip – and you’ll need some “TEXT2HTML” JavaScript and so on – which would be annoying.

But no – the amazingly simple tip is this :

  • Change the return type to be a NUMBER.

Yep.   If defies logic – and doesn’t make sense – might even be a BUG !

But – it works.

image

Take a bow

If you’ve done the steps correctly, it should look like this :

image

Too easy – right !!?!

** You might need to include the ‘site collection’ prefix within the formula – pro tip !

=”<DIV><img src='” & IF(Priority=1, “/sites/SC1/Style Library/IMG/red.png”, IF(Priority=2,”/sites/SC1/Style Library/IMG/yellow.png”, IF(Priority=3,”/sites/SC1/Style Library/IMG/green.png”, IF(Priority=4,”/sites/SC1/Style Library/IMG/blue.png”)))) & “‘></DIV>”

Next ideas

Check this blog for some other renditions – very cool !

http://sharepoint.alanchai.com/2012/05/conditional-formatting-for-list-sp2010.html

image

image

Let me know if you like this tip – my buddy DanCol was #MindBlown over this one !

🙂


Leave a comment

Copy files to every server (SharePoint)

Even with the ‘new era’ being Office 365, sometimes (!) we have to deal with an on-premises SharePoint farm – often with many servers.

The recent environment I was upgrading has over a dozen servers – and we had a need to copy a file to EVERY server.

This was simply a PDF icon image – but a pain-in-the-butt to copy to lots of locations.

The solution was to define an XML file with a list of servers, and some PowerShell to do the copying.

Make sure to save both files to the same folder – and the image file (in this situation).

SERVERS_LIST.XML (contents)

<servers>

<server>SPWB101</server>

<server>SPWB102</server>

<server>SPAP101</server>

<server>SPSSRS01</server>

</servers>

The PowerShell script does the following :

  • Open the XML file
  • Do a “Foreach” for the servers
  • Define the path for the file (destination)
  • Do a “Copy-Item” command – to each \\SERVER\C$\path

POWERSHELL

$xml = [xml] (Get-Content (resolve-path .\SERVERS_LIST.xml))

$currentPath = (resolve-path .\pdficon_small.png)

$servers = $xml.Servers.Server

$servers | % {

      $server = $_

      $path = “\\$server\C$\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\icpdf.png”

      Copy-Item $currentPath $path

}

 

This is a great option for a quick “deploy to every server” – as a scripted solution.

Hope this can be helpful / useful for your environment !

🙂