SharePointRoot


1 Comment

Add Geolocation Column to SharePoint

Unfortunately, the new “Geolocation” column in SP2013 doesn’t come ‘turned on’ by default.

I was able to easily add it as a ‘site column’ – and then can add to any list.

  • Open Visual Studio project
  • Create a C# console app
  • Add a reference to the following :
    • Microsoft.SharePoint.Client
    • Microsoft.SharePoint.Client.Runtime
  • Include the following code :

ClientContext context = new ClientContext(“https//server/site”);
Web web = context.Web;
context.ExecuteQuery();

var newField = web.Fields.AddFieldAsXml(“<Field Type=’Geolocation’ DisplayName=’Map GeoLocation’/>”, false, AddFieldOptions.DefaultValue);

context.ExecuteQuery();

After executing the project, you should be able to go back to SharePoint – and do the following ;

Edit properties of a list, and click “add from existing site columns” :

image
Choose the new column :

image

And there it is :

image

That’s about it – too easy, eh !?

** The same code should work for Office 365 – I haven’t tried it yet though – will update soon…


Leave a comment

Cannot select variables in Nintex Workflow (SP2010)

Have been looking into a strange occurrence, in which some variables can’t be chosen.   

The activity we’ve been trying is the FLEXI TASK and TO-DO TASK.

I’ve created a new Workflow – and added an activity :

image

Choose to configure the activity :

image

Where are the VARIABLES ??

image

I have a TEXT and a PERSON variable – see below :

image

BUT – these don’t show in the field chooser – WHY !!??

The problem :

I’m using Internet Explorer 11 – on Windows 8.1 – and the same happens on IE10.  

This doesn’t happen on IE9 though – so it’s a BROWSER issue !!

The other clue is that there are no save/cancel buttons :

image

The solution :

Firstly, SAVE the workflow – as the browser will need to reload the page.

Within IE11, you need to change the ‘compatibility’ setting.

image

Make sure to add the current URL (in my case : dev.local)

image

Click “Close” – and the browser will refresh.

The test

After re-loading the workflow – and checking the activity, it now works !

image

If you get this problem – or any JavaScript errors while working on a Nintex Workflow 2010 environment, check the ‘compatibility’ settings.

:-)


Leave a comment

Passing values INTO a SharePoint AppWeb (IFRAME)

The new application architecture for SharePoint 2013 is a big change, with the contents of an ‘app’ being contained within an IFRAME (old school for the new school !)

There are some challenges – most notably with ‘cross domain’ calls.

Much of the details on the web discuss HOW you can include JavaScript (CSOM) within the APP Web (inside the iframe) for calling to some parts of SharePoint – within the HOST Web.

Have a look at the great articles from Chris O’Brien – very good detail :

http://www.sharepointnutsandbolts.com/2012/11/access-end-user-data-in-host-web-from.html

BUT – what if you want to do the opposite ?    And pass values INTO the IFrame ?

Problem Statement

In the example below, there are some URL’s at play – for the main ‘outer browser page’ – and the SharePoint “AppPart” IFRAME SRC attribute – which will be detailed below.

image

The problem I have, is to pass the “CompanyId” and “Service” into the APP WEB.

Investigation

From looking at the ‘source’ of the page (with the AppPart), there is an IFRAME :

image

Looking at the source (SRC) for the IFRAME, there is a massive URL :

https://TENANT.sharepoint.com/_layouts/15/appredirect.aspx?redirect_uri=https%3A%2F%2Fa57e0d4b%2Db308%2D4d37%2D933f%2Df6ac34cc3caf%2Eo365apps%2Enet%2FPages%2FContactUs%2Easpx%3FSPHostUrl%3Dhttps%253A%252F%252Fsdfsdfsdf%252Dpublic%252Esharepoint%252Ecom%26SPHostTitle%3DWebsite%26SPAppWebUrl%3Dhttps%253A%252F%252Fsdfsdfsdf%252D0b8387559abd0a%252Esharepoint%252Ecom%252FExchangeBookings%26SPLanguage%3Den%252DUS%26SPClientTag%3D24%26SPProductNumber%3D16%252E0%252E2510%252E1213%26SenderId%3D43AA3E140%26%26CTYPE%3De%26EID=282&client_id=i%3A0i%2Et%7Cms%2Esp%2Eext%7Ca57e0d4b%2Db308%2D4d37%2D933f%2Df6ac34cc3caf%40691f8b90%2Df291%2D48a2%2Db6a4%2D173a73073f2c

In reality – it’s not THAT scary, when you break it down :

And so – what if we’re able to UPDATE the ‘redirect_uri’ to include the custom properties as mentioned above ??     Oooooh !   That might just work.

Proof Of Concept

The next bits cover the code I tried – using some JavaScript/jQuery – on the main page that I’m hosting the AppPart.

  • Add a “Script Block” and include the following :

<script type=”text/javascript” src=”/Style%20Library/jquery-1.10.2.min.js” ></script>

<script type=”text/javascript” src=”/Style%20Library/IFrameHelper.js” ></script>

  • Obviously – need to download jQuery.js, into Style Library
  • Then, within the code for the “IFrameHelper.js” do the following :
    • Use jQuery to run ‘on document load’
    • Get the current page URL (entire browser)
    • Get the QueryString part from main window (CompanyId / Service)
    • ADD this to the ‘redirect_uri’ piece
    • Put it back together
    • Update the SRC for the IFRAME
  • Params will now be passed INTO the IFRAME – and you can grab in C# code

The main change is to define a new URL :

And – this is updated as the SRC of the IFRAME.     The good bit is, that this will send ALL + ANY QueryString bits to the child IFRAME.

Here’s the full code of the “JS” file – PLEASE let me know if this helps you – or you managed to do this a nicer way (??)

image

Here’s the code in all it’s ugly wonder – not the best to read online (that’s why I put it as a screen shot above).

$(document).ready(function () {
    // get the current url – and the query string bit
    var currentPageUrl = window.location.href;

    // if there *IS* a query string – then need to grab – and pass on to the iFRAME
    if (currentPageUrl.indexOf(‘?’) != -1) {
        // —————————————————————
        // get the query string bit for current page
        // —————————————————————
        var currentPageQueryString = currentPageUrl.substring(currentPageUrl.indexOf(‘?’));

        //need to fix some bits with the querystring
        currentPageQueryString = currentPageQueryString.replace(“?”, “%26″);
        currentPageQueryString = currentPageQueryString.replace(“&”, “%26″);
        currentPageQueryString = currentPageQueryString.replace(“=”, “%3D”);

        // —————————————————————  
        // now update the iframe src
        // —————————————————————

        //get the url from iframe on page
        var src = $(‘iframe’).attr(‘src’);

        if (src != null) {
            //need to get the query string parts – esp.find the ‘redirect_uri’ – and APPEND some bits to it
            var iframeUrl = src.substring(0, src.indexOf(‘?’));

            var vars = getUrlVars(src);
            var redirectUrl = vars[“redirect_uri”];
            var clientID = vars[“client_id”];

            //add on the extra bit (for this page querystring)
            redirectUrl = redirectUrl + “%26″ + currentPageQueryString;

            //piece back together – and update the iframe
            var newUrl = iframeUrl + “?redirect_uri=” + redirectUrl + “&client_id=” + clientID;

            //update the SRC in the IFRAME
            $(‘iframe’).attr(‘src’, newUrl);

        }
    }

});

function getUrlVars(url) {
    //split up the pieces of the URL
    var vars = [], hash;

    var hashes = url.slice(url.indexOf(‘?’) + 1).split(‘&’);

    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split(‘=’);
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

NB.   I’m using this within Office 365 – but – it should be OK for an on-premises environment of SharePoint 2013.


Leave a comment

DispForm.aspx Error in Office 365

I’ve been tracking down a very wierd (!!!) problem with Office 365, and a SharePoint 2013 environment.  

From a few support calls with Microsoft, it turned out to be the ‘Master Page’ in use.

The basic symptom is as follows :

  • Create a custom SharePoint list – eg. Test List
  • Add a few items – at least 4-5 items
  • Click on the “View Item” dropdown

Error message shown :

Sorry, something went wrong

No item exists at https://TENANT.sharepoint.com/Lists/Test List/DispForm.aspx?ID=3&Source=https://TENANT.sharepoint.com/Lists/Test%2520List/AllItems.aspx&ContentTypeId=0x0100C960232A60E32F4A9E0F734CBF3C7428&RootFolder=/Lists/Test List.  It may have been deleted or renamed by another user.

Technical Details

Troubleshoot issues with Microsoft SharePoint Foundation.

Correlation ID: 73906e9c-bcaf-3050-c352-cfaf2db01581

But – the item is there – I can view within a REST URL :

https://TENANT/_vti_bin/listdata.svc/TestList(3)

And – the page ONLY works for VIEWITEM.ASPX?ID=1 and ?ID=2

Further wierdness – if I add a querystring to ANY page – it errors :

Eg.   https://TENANT/Pages/About-us.aspx?ID=1    (no problem – and ID=2)

https://TENANT/Pages/About-us.aspx?ID=3     (error !!)

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

For some reason, there is a problem with the “OSLO.MASTER” master page – in use for the SYSTEM master page.

If you try to VIEW – or EDIT a list item with ID > 2 (only #1 and #2 will work) – you get this error.

When I switched to the SEATTLE.MASTER master page, the problem went away.

WTF !?

image

I’ve spoken with a few Microsoft ppl – and some internal “Masters” (MCM) at my company – and we’re all a little bewildered by this behaviour.

I’ll need to look into it some more – and see which tags in the Master Page have caused this problem…

Anyone else noticed this problem ??     (or have an answer WHY !?)

** Will update soon – if/when I find an answer.

 

UPDATE :

From some trial+error, and plenty of WinDiff, and cut/copy/paste markup within SharePoint Designer, I finally determined the error.

There is a “DelegateControl” that is used in the OSLO master page, but not within SEATTLE.   

When I remove this, then all is OK.   

Add it back again, and the error returns.

<SharePoint:DelegateControl runat=”server” ControlId=”PageHeader” AllowMultipleControls=”false” />

The next question is – what does this delegate do ?    And, does it happen with SP2013 ‘on-premises’ also ??      More to investigate….


2 Comments

Video Player for SharePoint 2013 and Office 365

When needing to include some media content for a SharePoint 2013 site, there is an out-of-the-box video player that uses the new HTML5 VIDEO tag.

NB. I’m using the Public-Facing Anonymous website that is part of Office 365.

Choose a video :

image

Video player :

image

This is ‘nice’ – but is a little lacking – and not a good solution for a public facing site (anonymous) – and doesn’t play on an iPhone (FAIL !)

Alternative HTML5 video player

After some looking around, the best solution I’ve found is an extension to the HTML5 VIDEO tag – making use of the very-awesome, open-source – AND free – VIDEO.JS plug-in (just check the website link for a sample).

This uses some JavaScript to include some controls – and – works across browser, and most importantly, on an iPad/iPhone.

The steps I took were as follows :

(1) Get the files for VIDEO.JS 

I chose to download, and save these to STYLE LIBRARY – just to have them hosted on my site – rather than use the CDN – right-click and SAVE these files :

  1. video.js    (JavaScript)
  2. video-js.css    (CSS)
  3. video-js.swf    (Flash Plug-in)

 

Upload the above files to STYLE LIBRARY.

(2) Load the files to SharePoint 2013

You’ll also need to upload the following :

  • Video file – well, derrrr…       I’m using an MP4
  • JPG for the preview image – known as the ‘poster’ for VIDEO.JS

I put these last few files into SITE ASSETS

(3) Add the SCRIPT for the video player

On the page you want to show the video, include an “Embed Code” webpart.

Here’s the tags you need for the JS, CSS and SWF :

<link href=”/Style%20Library/video-js.css” rel=”stylesheet”></link>

<script type=”text/javascript” src=”/Style%20Library/video.js”></script>

<script>

videojs.options.flash.swf = “/Style%20Library/video-js.swf”

</script>

(4) Include the VIDEO tag

I had to tweak and fine-tune the examples from the site for VIDEO.JS.

With regard to the VIDEO tag for SharePoint – or more specifically, the “Embed Code” dialog/editor strips out some tags/text – specifically the ‘controls’ tag.

HTML5 allows you to have the attribute controls which implies a default of ‘True’.  

SharePoint will remove that – so you have to explicitly set controls=’true’.

The other piece was the surrounding DIV to make sure that the ‘overflow’ was hidden – otherwise, the Safari browser on iOS will display the window the same size as the original video dimensions – irrespective of the size entered.

Here’s the HTML you’ll need :

<div style=”width:576;height:324;overflow-x:hidden;overflow-y:hidden;”>

<video id=”SPvideo” class=”video-js vjs-default-skin vjs-big-play-centered” preload=”auto” data-setup=”{‘example_option':true}” controls=”true” poster=”/SiteAssets/VideoPreviewFrame.jpg” height=”324” width=”576“>
<source type=”video/mp4″ src=”/SiteAssets/MyCoolVideo.mp4“>
</video>

</div>

(5)  Change if you need

Of course, you can tweak and fine-tune as you need – with regard to :

  • Width + Height – make the outer DIV the same as the VIDEO tag (obviously)
  • Poster – I just did a screenshot of the video (full screen), and resized it to be the same width/height – 576×324 for my example
  • The URL to the video of course – you can try with a WEBM format, or whichever you like, according to the HTML5 VIDEO tag.
  • CSS and other bits
  • Any other VIDEO.JS extensions and such – check the DOCS + API reference.

(6) The final product

After I’d implemented the above, the player looks like this :

image

This is within an anonymous site on Office365 – just make sure you ‘publish’ the files for CSS, JS and SWF.

The player on iOS shows the preview image, and then uses the iPhone video player.

Good luck – let me know if this helps – pls. leave me a comment.

:-)


Leave a comment

DataVisualization.Charting using ASP.NET and C#

As part of a recent SharePoint project, we have been needing to generate graphs/charts for inclusion on a webpage – as well as via code to save and include in a Microsoft Word document (DOCX).

The best option we found was the Microsoft .NET charting controls :

System.Web.UI.DataVisualization.Charting

To get this working within an ASP.NET project, I had to source information from a few blog posts – and it was a little tricky – so I thought I’d blog about it here.

(1) Within your Visual Studio WebApp Project, add a reference to the required DLL’s :

System.Web.DataVisualization

image

(2) Add an IMAGE placeholder control to your ASP.NET markup :

<asp:Image ID=”imgChart” runat=”server” />

(3) Within code, include the *using* statement, and then the necessary code for charting.   

using System.Web.UI.DataVisualization.Charting;

(4) The trick I found was to made sure the chart control did a ‘RenderControl’ – and then you can use the CurrentImageLocation reference.

private void ShowChart()
{
    // set up some data
    var xvals = new[]
    {
        new DateTime(2012, 4, 4),
        new DateTime(2012, 4, 5),
        new DateTime(2012, 4, 6),
        new DateTime(2012, 4, 7)
    };

    var yvals = new[] { 1,3,7,12 };

    // create the chart
    var chart = new Chart();
    chart.Height = 600;
    chart.Width = 600;
    chart.RenderType = RenderType.ImageTag;

    //set the chart properties
    var chartArea = new ChartArea();
    chartArea.AxisX.LabelStyle.Format = “dd/MMM\nhh:mm”;
    chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
    chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
    chartArea.AxisX.LabelStyle.Font = new Font(“Consolas”, 8);
    chartArea.AxisY.LabelStyle.Font = new Font(“Consolas”, 8);
    chart.ChartAreas.Add(chartArea);

    var series = new Series();
    series.Name = “Series1″;
    series.ChartType = SeriesChartType.FastLine;
    series.XValueType = ChartValueType.DateTime;
    chart.Series.Add(series);

    // bind the datapoints
    chart.Series[“Series1″].Points.DataBindXY(xvals, yvals);

    // render to a HTML writer
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    chart.RenderControl(hw);

    //can now grab the URL to the asp:image
    imgChart.ImageUrl = chart.CurrentImageLocation;

}

(5) Run the solution – and you should see the page like this :

image

** Many thanks to the TIM BARRASS for the following post for much of the details – was just the ‘ASP.NET’ aspect that I had to work out – his blogpost was using the Windows.Forms components.  

The bits in RED above are the main differences.

Creating a chart programmatically in C# using DataVisualization.Charting


Leave a comment

SharePoint Calculated Column value -329378600

When migrating to SharePoint 2013, there are some differences that may impact when checking calculated columns.

We had a list/library that was from SharePoint 2007.

In the following (complicated) example, the ‘end value’ was wrong :

=IF([Action 2 When]=””,””,IF(AND([Action 2 When]>=[Last Report Date],[Action 2 When]<=[Todays Date]),”Newly Late”,IF([Action 2 When]<[Last Report Date],”Still Late”,”On Time”)))

The value was being shown as :

;#-329378600

WTF ?

It turned out that this was an EXCEPTION code – and the formula was getting null’ed out somewhere along the line.

The answer was to make sure to put “space” in an empty value :

=IF([Action 2 When]=””,” “,IF(AND([Action 2 When]>=[Last Report Date],[Action 2 When]<=[Todays Date]),”Newly Late”,IF([Action 2 When]<[Last Report Date],”Still Late”,”On Time”)))

Very subtle different – but it seems to resolve the problem (!)

HTH.   :-)

Follow

Get every new post delivered to your Inbox.

Join 31 other followers