Sharepoint - Infopath's built in Username() function returning "i:0#.w|Domain\UserName" instead of just UserName?

The reason you're seeing this is that your production farm uses Claims AuthN whereas your dev enviroment the classic mode. You should probably make your code handle both scenarios.

Here are some details about the claims encoding: http://www.wictorwilen.se/Post/How-Claims-encoding-works-in-SharePoint-2010.aspx


While researching this myself, I found a solution that might be a bit better than a substring. You might want to try the following:

SPClaimProviderManager manager = SPClaimProviderManager.Local;

if (manager != null)
{
    if (SPClaimProviderManager.IsEncodedClaim(encodedString))
        username = manager.DecodeClaim(encodedString).Value;
    else
        username = encodedString;
}

Try a substring after "\" for the user name, or after "|" for the domain and user name.

http://office.microsoft.com/en-us/infopath-help/functions-in-infopath-HP001155281.aspx

Tags: