SharePoint 2010 Ribbon Development

Ribbon development is probably one of the most frustrating things you can do when developing SharePoint 2010 solutions, for one simple reason.

How many times have you changed the element.xml file to change where your new button will appear only to find that no matter how many times you deploy, there it is, in exactly the same place.

You might try:

  1. Retracting the solution in Visual Studio 2010.  Won’t work.
  2. Using PowerShell, Uninstall-SPUserSolution then Remove-SPUserSolution.  Won’t work.
  3. Restart the sandbox service, NET STOP SPUserCodeV4, then start again.  Won’t work.
  4. Check out C:ProgramDataMicrosoftSharePointUCCache and (against all advice), clean it out. Won’t work.
  5. Swearing at the laptop.  Won’t work (I tried this one lots).

After countless Internet searches I’ve found two solutions, and fortunately, they’re really simple:

  1. Update the feature version each deployment.
  2. Test out the site using InPrivate mode, or equivalent, in the browser; close the window and restart again between deployments.

Original articles SharePoint 2010 Ribbon customizations not working as expected and SharePoint 2010: Modifying and Deploying Ribbon doesn’t update the ribbon.

Posted in SharePoint | Leave a comment

Estimating SharePoint 2010 Content Database Sizes

Microsoft published guidance for SharePoint 2010 on how to calculate an estimated size of a content database.

The formula is very simple:

Database size = ((D × V) × S) + (10 KB × (L + (V × D)))

On the train to work this morning I wrote a little bit of JavaScript to help automate this calculation.  You can try it out live here, or grab the code below for yourself.

[js]
function UpdateDBSize() {
// Pull all the data and elements that we’re going to need in to local variables
var d = document.getElementById(“capcalc_D”).value;
var s = document.getElementById(“capcalc_S”).value;
var l = document.getElementById(“capcalc_L”).value;
var v = document.getElementById(“capcalc_V”).value;

var dErrMsg = document.getElementById(“capcalc_DErrMsg”);
var sErrMsg = document.getElementById(“capcalc_SErrMsg”);
var lErrMsg = document.getElementById(“capcalc_LErrMsg”);
var vErrMsg = document.getElementById(“capcalc_VErrMsg”);

// Validate each number, set error message visibility if not
var allValid;
allValid = Validate(d, dErrMsg);
allValid = allValid & Validate(s, sErrMsg);
allValid = allValid & Validate(l, lErrMsg);
allValid = allValid & Validate(v, vErrMsg);

var answerElemKB = document.getElementById(“capcalc_answerKB”);
var answerElemMB = document.getElementById(“capcalc_answerMB”);
var answerElemGB = document.getElementById(“capcalc_answerGB”);

if (!allValid)
{
answerElemKB.innerHTML = “N/A”;
answerElemMB.innerHTML = “N/A”;
answerElemGB.innerHTML = “N/A”;
} else {
// Convert all to numbers
d = parseInt(d);
s = parseInt(s);
l = parseInt(l);
v = parseInt(v);

var dbSizeInKB = (d * v * s) + (10 * (l + (v * d)));
var dbSizeInMB = (dbSizeInKB / 1000).toFixed(2);
var dbSizeInGB = (dbSizeInKB / 1000000).toFixed(2);

answerElemKB.innerHTML = dbSizeInKB.toString().replace(/B(?=(?:d{3})+(?!d))/g, “,”) + ” KB”;
answerElemMB.innerHTML = dbSizeInMB.toString().replace(/B(?=(?:d{3})+(?!d))/g, “,”) + ” MB”;
answerElemGB.innerHTML = dbSizeInGB.toString().replace(/B(?=(?:d{3})+(?!d))/g, “,”) + ” GB”;
}
}

function Validate(val, errMsgElem) {
if (isNaN(val)) {
errMsgElem.innerHTML = ‘Please enter a non-negative integer’;
errMsgElem.style.color = “Red”;
return false;
} else {
errMsgElem.innerHTML = ‘OK’;
errMsgElem.style.color = “”;
return true;
}
}
[/js]

Operand Mnemonic Value Value OK?
Number of Documents D
Average Size of Document (KB) S
Average Number of List Items L
Average Number of Versions V
Database size = ((D * V) * S) + (10KB * (L + (V * D))) =

[js] UpdateDBSize(); [/js]

Let me know if you find this useful, or spot anything wrong!

Posted in JavaScript, SharePoint, Tools | Leave a comment

Encoding base-N numbers using custom digits

It’s been almost a year since I had to code in anger.  I wanted to do some compression on an XML document by shortening element and attribute names to the bare minimum.  The documents I’m compressing contain an unknown number of element names (could be 5, could be 30,000).

To do this, I decided to use a Huffman encoding for the element names, then convert them to an allowable name.  I’m not going to go in to the Huffman bit, so for the sake of simplicity let’s call the first element “1”, the second element “2”, the third element “3”, and so on.

The problem is that name elements in this way doesn’t work very well for two reasons:

  1. You can’t start an XML element name with a number.
  2. Once you’ve hit your tenth element, you’re now in to two character element names; i.e. we’ve not used all the available characters.

So, I decided to encode them in Base 52, using the “digits” ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwxyz.   So the first element would be “A”, then “B”, then the 27th would be “a”, the 53rd “AA”, then “AB”, etc.

Of course, I could be more clever and allow digits or valid punctuation characters in positions other than the first, but that would be too much for a Tuesday afternoon.  Also, I guessed at the valid starting characters for an XML element.  When I go and look it up and find I made a mistake, what then?  What if I wanted to change it? Or move to a completely different base, like binary, for another project?

Anyway, without further ado, the method is as follows:

public string GetEncoding(long numberToEncode, string vocab)
{
    int numberBase = vocab.Length;
    long total = numberToEncode;
    StringBuilder encodedNumber = new StringBuilder();
    int columnNumber = 0;
    while (Math.Pow(numberBase,columnNumber+1) <= total) columnNumber++;
    while (total > 0 || columnNumber>=0)
    {
        int colValue = (int) Math.Pow(numberBase, columnNumber);
        encodedNumber.Append(vocab[((int)total / colValue)]);
        total -= ((total / colValue) * colValue);
        columnNumber-- ;
    }
    return encodedNumber.ToString();
}

This can be used for any base you like, using any single character representations for digits.  For example:

GetEncoding(0, "01");
GetEncoding(1, "01");
GetEncoding(2, "01");
GetEncoding(3, "01");
GetEncoding(4, "01");
GetEncoding(5, "01");

GetEncoding(5, "0123456789");   // Yes, I'm aware how boring this is, but it's a good test
GetEncoding(27, "0123456789");
GetEncoding(546, "0123456789");

GetEncoding(16, "0123456789ABCDEF"); // Hexadecimal
GetEncoding(32, "0123456789ABCDEF");

GetEncoding(45243256, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");

Rather than attempt to explain how to use it, here are some sample invocations:

… and the outputs:

0
1
10
11
100
101

5
27
546

10
20

GJnyg
Posted in C#, Hints and Tips | Leave a comment

Mobile browsing on SharePoint, it’s not just for mobiles!

SharePoint sites do suffer from performance problems from time to time.  Perhaps the link between clients and WFE’s is congested, or the architects didn’t quite anticipate the usage patterns of their users, or maybe the orbit Neptune is wrongly aligned to the galactic plane.

Quite often a large amount of the time SharePoint spends spinning that busy icon round and round in circles is due to the sheer amount of data and number of web parts involved in rendering a single web page.  Most of which are probably fluff (for example, the company’s share price or logo).  However, you can cut all but the essential data by browsing the “mobile​ site” instead from a regular browser.

To do this, simply add mobile=1 as a query parameter to the URL you’re trying to access.  This works even for browsing content such as Word Documents (it’s not great, but it does its best, bless it).

Examples:

Home Page: http://www.example.com/?mobile=1

A Shared Documents Library: https://www.example.com/sites/Shared%20Documents/Forms/AllItems.aspx?mobile=1

I’ve tried this on several sites and been surprised at just how fast SharePoint can serve up the stuff that’s really important!

Posted in Hints and Tips, SharePoint | Leave a comment

Is “Automatic Logon with current user name and password” a type of Single Sign-on (SSO)?

Martin Hatch published a tweet this morning which caught me in a philosophical mood.  Very simply it was:

“fed up of people referring to “automatic logon with current user name and password” options in IE as being “Single Sign On” !”

This feature of IE is documented here.

This got me wondering as to why this is the case, i.e. why isn’t “automatic logon with current user name and password” a type of single sign-on?  Martin’s justification was that  because the browser is signing in more than once.  Hence, the “single” part of SSO is violated, i.e. it’s not SSO.  All perfectly logical.

However, even though that’s what is happening in the background, from the user’s perspective they have signed on exactly once (when they logged in to the machine).  The user didn’t have to sign on to the remote service.  They performed a single sign on, so it to them it is SSO.

Unfortunately, like many words in technology, there’s a lot of mud in the water because no-one owns the definition of “Single sign-on”.  So, as a quick exercise in curiosity, I decided to look up definitions of SSO on Google and see what the most highly-ranked pages said:

Open Group Single sign-on (SSO) is mechanism whereby a single action of user authentication and authorization can permit a user to access all computers and systems where he has access permission, without the need to enter multiple password
Wikipedia Single sign-on (SSO) is a property of access control of multiple related, but independent software systems. With this property a user logs in once and gains access to all systems without being prompted to log in again at each of them.
SearchSecurity Single sign-on (SSO)is a session/user authentication process that permits a user to enter one name and password in order to access multiple applications.
OCLC Developer Network Too long to repeat here, but a great read!
IST Knowledge Base Single Sign On (SSO) is a session/user authentication process that allows a user to provide his or her credentials once in order to access multiple applications.
Authentication World Single Sign On (SSO) (also known as Enterprise Single Sign On or “ESSO”) is the ability for a user to enter the same id and password to logon to multiple applications within an enterprise.

I was really surprised by variations in these definitions: some define it in terms of what actually happens (i.e. it isn’t SSO) and some in terms of the user experience (i.e. it is SSO).

I think that from these results it is to be expected that people are confused by SSO.  Like countless terms and phrases before it that get fed through the marketing-speak mangle, SSO will end up meaning different things to different people.  But if I had to justify why I thought that passing user credentials to a third party service wasn’t SSO, I’d say this:

“SSO happens when when a user is authenticated once to access several services; as opposed to a user being automatically re-authenticated when connecting to other systems.”

Both look the same from the user’s perspective, but something very different is happening behind the scenes.

Posted in Microsoft, Security | Tagged | Leave a comment

Subtracting days from a DateTime object in PowerShell

For those unfamiliar with DateTime objects, the problem is exceedingly simple – but the solution is even simpler.

Take the following DateTime object:

PS C:UsersAbrodie> $dt = get-date
PS C:UsersAbrodie> $dt

03 November 2011 17:48:56

If I look at the methods available, you can see there’s a conveniently long set of Add methods, enough to satisfy your every whim:

PS C:UsersAbrodie> $dt | Get-Member -MemberType Method | Format-Wide

Add                                                                             AddDays
AddHours                                                                        AddMilliseconds
AddMinutes                                                                      AddMonths
AddSeconds                                                                      AddTicks
AddYears                                                                       
CompareTo
Equals                                                                          GetDateTimeFormats
GetHashCode                                                                     GetType
GetTypeCode                                                                     IsDaylightSavingTime
Subtract                                                                        ToBinary
ToFileTime                                                                      ToFileTimeUtc
ToLocalTime                                                                     ToLongDateString
ToLongTimeString                                                                ToOADate
ToShortDateString                                                               ToShortTimeString
ToString                                                                        ToUniversalTime

All those lovely Add* methods, but only one subtract, which takes a TimeSpan object.

I found the following very useful blog entry on Powershell.nu, which details how to construct a TimeSpan instance and pass it to the Subtract method.

However, easiest way to perform a subtraction is simply to use arithmetic logic.  I.e.

PS C:UsersAbrodie> $dt.AddDays(-1)

02 November 2011 17:48:56

If you heard a slight cracking sound, as if a hand slapped a forehead quite hard, around 7:23am on Thursday 3rd November, that was me!

Posted in Hints and Tips, Microsoft, PowerShell | Tagged , | Leave a comment

Strange text behaviour in Visio 2003/2010

Network Diagrams in Visio are extremely useful when trying to design or explain to someone how a set of computers are, or are going to be, connected together.  The user is presented with a set of preset shapes which you can drag to the canvas.

Once on the canvas, simply click or press F2 and start typing to add a text label underneath the shape, like so:

 

Server with text label underneath

Correct positioning of text

Great, isn’t it?  What could be simpler?

Except, about 6 months ago on Visio 2010, then again last week on Visio 2003, instead of the text label appearing underneath the shape, instead it put it over the top, like this:

My Server with text label on top

This is not useful

Using the yellow diamond text anchor didn’t work either, it just sent the text shooting up and down diagonally down and left to top and right. This really wasn’t what I wanted, so after F1 and some unsuccessful searching, I turned to Bing and Google, but still nothing.  I’d hit this problem twice for what I’m pretty sure were unrelated reasons; maybe occasionally Visio sometimes has a senior moment?

After much clicking I came across the ShapeSheet.  This contains loads of cool power-user configurable items on your shape.  Having a peruse through the list of configurable items, I came across TxtPinX and TxtPinY:

The Text Transform group of the ShapeSheet

TxtPinX and TxtPinY of the ShapeSheet items for my shape

Adding a .Y to TxtPinY fixed the problem and put the text back where it should be:

Text Transform items with corrected TxtPinY

Corrected the TxtPinY

Problem solved… for that one shape. Unfortunately, the next server I added had the same problem. So, to fix it for all shapes, I had to edit the document stencil and make the change on the master shape intself. See Resources below for links to Visio documentation that explains this.

Resources

Resource Link
Visio 2010 ShapeSheet Reference http://msdn.microsoft.com/en-us/library/ff768297.aspx
Edit a master shape http://office.microsoft.com/en-us/visio-help/edit-a-master-shape-HA101827309.aspx
Posted in Hints and Tips, Microsoft, Visio | Leave a comment