0

I am assigning the spuserobject.Name in to a string. The out put of this is "FirstName,Lastname, . When i try to split it is not splitting the values can you tell me why?

     for (int i = 0; i < grpUserNames.Count; i++)
                    {
                        SPUser user = mySiteWeb.EnsureUser(Convert.ToString(grpUserNames[i]));


                        string email = user.Email;
                        string UN = user.Name;
                        String[] arr = UN.Split(',');
                        String last = arr[arr.Length - 1];
}
1

For FBA: userName = SPClaimProviderManager.Local.DecodeClaim(loginName).Value; For Windows: userName = SPClaimProviderManager.Local.ConvertClaimToIdentifier(loginName);

Hope it helps!

0

Your users are in Active Directory or comes from FBA?

If you are in active directory you have to ensure that grpUserNames are in the form "DOMAIN\USERALIAS"

You could try this

SPClaimProviderManager cpm = SPClaimProviderManager.Local;

for (int i = 0; i < grpUserNames.Count; i++)
{
    SPClaim userClaim = cpm.ConvertIdentifierToClaim(grpUserNames[i], SPIdentifierTypes.WindowsSamAccountName);
    SPUser user = mySiteWeb.EnsureUser(userClaim.ToEncodedString());


    string email = user.Email;
    string UN = user.Name;
    String[] arr = UN.Split(',');
    String last = arr[arr.Length - 1];
}

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.