Author Archives: dannymelia

About dannymelia

Women want me. Men want to be me. Animals want to learn how to talk so they can hang out with me. I'm trying the sunglasses on in the shop which is why there is a label on my face.

Finding an accounts Organisational Unit in AD U&C

Have you ever opened up Active Directory Users and Computers, happily searched for, viewed, and edited an item’s properties, but simply been unable to find its Organisational Unit in any kind of straight forward manner?! Scouring through the tree view on the left or googling round for commands is just not feasible. Should be straight forward – this is something that seems like a massive (and annoying) oversight by the developers.

Well…gotcha! What you need is the ‘Object’ tab on the item’s properties; this displays its Canonical Name which has a format,

‘Domain/organisationalUnit/accountOrComputer’

However you can only view this tab if you have ‘View’ -> ’Advanced Features’ selected in the main U&C window.

Man, it’s the little things.


Embedded Explorer View Not Working

Symptoms

Explorer View fails to launch when it is selected from the ‘Views:’ drop down on the top right of the document library web part (this is opposed to launching Explorer View by clicking ‘Actions’ -> ‘Open with Windows Explorer’).

In IE7 this should display Windows Explorer on the page itself embedded in an iframe, when this problem occurs the iframe displays a blank page instead. IE8 and IE9 a separate Windows Explorer window should be opened but the problem means it fails to do so.

Resolution

Upon selecting Explorer View the page does a post back and the JavaScript function that launches it (called ‘navtoframe2′) is meant to be called by the body’s onload event.

How this actually works:

The body element is contained in the master page while the document library itself will be in one of many content pages, these content pages also could have any number of functions on them that need to be called by the same onload event. Microsoft’s way of accomplishing this is by adding their names to a global array called ‘_spBodyOnLoadFunctionNames’ while the page is loading.

The master page’s onload event actually calls ‘_spBodyOnLoadWrapper()’, contained within the ‘LAYOUTS\1033\INIT.JS’ file, this goes through ‘_spBodyOnLoadFunctionNames’ calling each function.

The client’s issue was that someone had deleted the onload attribute from the body tag of a de-ghosted master page, this was a fairly easy fix by having them re-add it.

onload=”javascript:if (typeof(_spBodyOnLoadWrapper) != ‘undefined’) _spBodyOnLoadWrapper();”

While we’re on the subject of the onload event a good tip is to stay away from the window.onload property when working with SharePoint as this will be overwritten by the body’s onload attribute. I imagine JQuery’s (rather excellent) .ready() function would cause problems too.


My Site Storage Quota Exceeded

Symptoms

User reports that their My Site storage limit has been reached (‘_layouts/storman.aspx’) even though they have used less space than their actual quota.

Resolution

The first thing to look at here is whether they have items in their recycle bin since this counts against their total quota:

http://personal/_layouts/recyclebin.aspx

However from this view you will only be able to see documents you have deleted yourself; instead go to,

http://personal/_layouts/adminrecyclebin.aspx

Once you or the user has deleted these items they will be moved to the site collection (i.e. secondary) recycle bin.

http://personal/_layouts/adminrecyclebin.aspx?View=2

This has it’s own quota that can be set from central admin at the web application level (go to ‘Application Management’ -> ‘Web Application General Settings’).

We had an issue like this passed on to us (2nd/3rd line support) with the user claiming they had emptied their recycle bin but that their My Site was still full.

It turns out the client had a mapping between their users’ My Sites and a folder on their desktops; to clear space the user had deleted some documents from this folder (using Windows Explorer) and when asked to empty her recycle bin had done so on her own computer rather than in SharePoint!


Javascript Twitter feed

I wrote a Javascript Twitter feed recently to display a single tweet on my website. Thought I’d try it without using JQuery for a change.

Easy!

However I wanted to do it all in my browser but using JSONP to get the tweet seems to take ages – I’m going to try calling their service from the server instead (back to the old C# then).

I don’t think I’ll be using this but it was fun to make. If anyone would like to give it a try here it is.

The html:


<div id="twitter-feed">
    <div id="twitter-heading">
        <div id="twitter-waiting">Loading content...</div>
        <div id="twitter-date"></div>
    </div>
    <p id="twitter-content"></p>   
    <!-- follow button here -->
</div>

A follow button generator can be found here.

The code:


<script type="text/javascript"> // twitter feed

    var maxCharacters = 100; // maximum number of tweet characters you want to display
    var numberOfTweets = 10; // the number of tweets you want to fetch
    var screenName = "danny_melia";  // the screen name of the account you want tweets from
    var includeRetweets = true;  // include retweets amongst the tweets fetched

    // Processes and displays JSONP
    function handleResponse(responseJson) {

        var tweet;
        var date;
        var i = 0;

        // gets the tweet
        try {
            if (responseJson[i].text != null && responseJson[i].text != "") {

                tweet = responseJson[i].text;
            }
            else {

                for (i = 1; i < 10; i++) {

                    if (responseJson[i].text != null && responseJson[i].text != "") {

                        tweet = responseJson[i].text;
                        break;
                    }
                }
            }

            // gets the date
            var dateList = responseJson[i].created_at.split(" ");
            var day = dateList[2];
            var month = dateList[1];
            var year = dateList[5];

            // replaces the month's name with a number 
            switch (month) {
                case "Jan": month = "01"; break;
                case "Feb": month = "02"; break;
                case "Mar": month = "03"; break;
                case "Apr": month = "04"; break;
                case "May": month = "05"; break;
                case "Jun": month = "06"; break;
                case "Jul": month = "07"; break;
                case "Aug": month = "08"; break;
                case "Sep": month = "09"; break;
                case "Oct": month = "10"; break;
                case "Nov": month = "11"; break;
                case "Dec": month = "12"; break;
                default:
            }

            date = day + "." + month + "." + year;

            // formats the tweet
            if (tweet.length > maxCharacters) {

                var j = maxCharacters;

                while (tweet.charAt(j - 1) == ' ') {

                    j--;
                }

                tweet = tweet.substring(0, j) + "...";
            }

            // checks for problems
            if (tweet == null || tweet == "" || date == null || date == "") { throw ""; }
        }
        catch (err) {
            date = new Date();
            var d = date.getDate();
            var day = (d < 10) ? '0' + d : d;
            var m = date.getMonth() + 1;
            var month = (m < 10) ? '0' + m : m;
            var y = date.getYear();
            var year = (y < 1000) ? y + 1900 : y;
            date = day + "." + month + "." + year;

            if (tweet == null || tweet == "") {

                tweet = "Content could not be found.";
            }
        }
        finally {
            // updates the page
            document.getElementById("twitter-waiting").style.display = "none";
            document.getElementById("twitter-date").innerHTML = date;
            document.getElementById("twitter-content").innerHTML = tweet;
        }
    }

    // gets JSONP
    window.onload = function () {

        var jsonpScript = document.createElement("script");
        jsonpScript.type = "text/javascript";
        jsonpScript.src = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + screenName + "&include_rts=" + includeRetweets + "&count=" + numberOfTweets + "&callback=handleResponse"
        document.body.appendChild(jsonpScript);
    }

    window.onunload = function () { }
        
</script>

SharePoint folders with dodgy names

A client had a nice little problem today:

Symptoms

You can’t open any of the documents in a particular folder. After clicking on a document in your browser the application launches (e.g Word) but its URL can’t be found and it is not opened.

You can’t open the folder in explorer view, when you enter explorer view from the document library or a parent folder and drill down to it you find that it is empty.

Resolution

This problem occurred for a folder named,

“Meetings + Admin Papers”

As you can see it includes the ‘+’ character (which is URI reserved). The URL’s that SharePoint was using for documents within it actually contained the character itself rather than percent encoding it and this was causing a problem somewhere along the line.

Changing the folder’s name to “Meetings and Admin Papers” resolved this right away.

Moral of the story – watch out for suspicious characters.


Follow

Get every new post delivered to your Inbox.