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 ..

link|improve this question
feedback

1 Answer

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.

link|improve this answer
thats one crazy class I didn't know it existed... Nice one :) – Frederik P. Feb 17 at 15:39
feedback

Your Answer

 
or
required, but never shown

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