Thursday, February 12, 2015

IE8 can’t handle split by regex

FYI, this is a very strange bug I just stumbled upon in IE8, even other IE versions running in IE8 mode (which means – anyone using IE with SharePoint 2010)…

It appears while IE8 can handle a simple string split by character, such as “a,b,c,d”.split(“,”) – it is having a really hard time working with a regular expression split.

It is supposed to be supported, it is working on any other browser including IE9+…

Here is what I have, splitting a string by matching tokens inside [ ]:

var arr = str.split(/\[(.*?)\]/);

All browsers will return all text before, inside and after the matches.

IE8, it appears, is the only one out of the bunch not returning the text inside the token.

BTW, if you ask me – IE8 is the only browser who is actually doing what I asked – which is to split by the match, while I would say all other browsers are in the wrong – splitting by the matches themselves in the regex… but if all browsers do one thing and IE8 does another, it just makes it impossible to rely and use this API.

Well, off to find another solution.

Monday, January 26, 2015

Strange user login name in SharePoint when using Claims?

Hey, if you are like me and use claims to login to your SharePoint, you probably noticed the user names went nuts.

Having a user name like domain\user will now return something more like i:0#.w|domain\user if you are lucky, but I’ve seen stranger formats as well…

Now, say a user sends you a login name (domain\user) and you need to get this value and set it to the assigned to of a task, or set permissions for this user – you will quickly find out you cannot get an SPUser object from this standard login name.

Also, when you want to send the login name to another system or work with it in your code – you might want to get just the domain\user part, without the claims decorations.

True, the claims login formats are documented and you can hope to parse the format yourself to extract the user login from it, but I recently found a hidden (to me at least) gem in SharePoint API that can help with this task.

First, start using this namespace: Microsoft.SharePoint.Administration.Claims;

Now, you can work with SPClaimProviderManager object to check if a string is a claims encoded user name, and convert it to a standard user name, and the other way around.

I’ve created this simple utility class for me to use in my code for now, here is a code sample explaining how to use this object:

public class ClaimsHelper
{
    public static string ClaimsToLogin(string login)
    {
        try{
            if(SPClaimProviderManager.IsEncodedClaim(login))
                return SPClaimProviderManager.Local.ConvertClaimToIdentifier(login);
        }
        catch{
            //log error, return the origina value we got
        }
        return login;
    }
    public static string LoginToClaims(string login)
    {
        try
        {
            if (!SPClaimProviderManager.IsEncodedClaim(login))
                return SPClaimProviderManager.Local.ConvertIdentifierToClaim(login, SPIdentifierTypes.WindowsSamAccountName).ToEncodedString();
        }
        catch
        {
            //log error, return the origina value we got
        }
        return login;
    }
}

(Code is for example purposes only, use at own risk, feel free to change the names of the helpers)


Notice I’m expecting to get a windows login user name (SPIdentifierTypes.WindowsSamAccountName) but you can change this to support your own authentication.


Good luck, hope this help.

Tuesday, January 20, 2015

Proudly Canadian?

Great! So am I.
So, visit our site and get your choice of a free SharePoint product:
http://www.kwizcom.com/special-offers/canadieneh/
Canadian_campaign_800_320
My personal favorites you should be looking at:
  1. Data View Plus – since it is the Swiss army knife of all SharePoint viewers out there!
  2. List inline editor – I use it all the time, this one saves me literally hours of data entry or updating bugs every single day.
  3. Forms w/Custom actions – need I say more?? If you don’t know what its all about, check out this quick video http://www.kwizcom.com/sharepoint-add-ons/sharepoint-list-custom-actions/overview/
  4. Wiki Plus – Company procedures? Publish articles? Want to be able to use *real* wiki language with quick TOC?
Wow – it was hard coming up with just 4, anyway – one is yours to keep for free. Sound off in the comments for questions or feedback (guys, no support questions here please – for that visit http://support.kwizcom.com/Default.aspx or http://forum.kwizcom.com/Default.aspx as I can’t really help you in the comments)