1

I have an UserProfile object for the user john.

His LoginName is company\john.

i'm able to get it by objUserProfile["AccountName"].Value;

Now, i want to get details from the SPWeb object using this account name. but i'm unable to get it. Because in sharepoint the login name for that user is i#w:company\john. As i have enabled windows and farm-based authentication in my webapp, it is showing the loginname as i#w:company\john. But in userprofile object it is showing only company\john. What is the right way to access the details from sharepoint. Any suggestion please ..

1 Answer 1

5

You can convert claim format into login name with:

string userName = null;
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null)
{
    userName = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value;
}

and convert login name into claim format with:

string userName = null;
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null)
{
    SPClaim claim = new SPClaim(SPClaimTypes.UserLogonName, "myuser", "http://www.w3.org/2001/XMLSchema#string", SPOriginalIssuers.Format(SPOriginalIssuerType.Forms, "myprovider"));
    userName = mgr.EncodeClaim(claim);
}

Source

More details of the SPClaimProviderManager from MSDN.

2
  • 2
    thats one crazy class I didn't know it existed... Nice one :) Feb 17, 2012 at 15:39
  • 1
    +1 - this has been frustrating me for about an hour. I thought I'd have to start regex'ing the bloody thing out!
    – TZHX
    Oct 19, 2012 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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