By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,537 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,537 IT Pros & Developers. It's quick & easy.

How to retrieve user profile property in sharepoint 2010.

P: 1
I have to retrive User Profile Property of logged in User in SharePoint 2010.First I retrieve User's login name then I assign the value to GetUserProfile() method.

Expand|Select|Wrap|Line Numbers
  1. String _AccountName = Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.LoginName;
When I did the follows , I got error-"An error was encountered while retrieving the user profile".

Error: UserProfile userProfile = profileManager.GetUserProfile(_AccountName);
Error: UserProfile userProfile = profileManager.GetUserProfile("_AccountName");
Error: UserProfile userProfile = profileManager.GetUserProfile("Doamin\UserName");//[Hardcoded UserLogin Name]

Success: UserProfile userProfile = profileManager.GetUserProfile("Domain\\UserName");
because single '\' wont take.

Now I have to retrive Account Name and assign in
Expand|Select|Wrap|Line Numbers
  1. UserProfile userProfile = profileManager.GetUserProfile(?)
I write the follow

Expand|Select|Wrap|Line Numbers
  1. string[] userDomainName=_AccountName.Split('\\');
  2. string domain = userDomainName[0];
  3. string Name = userDomainName[1];
  5. System.Text.StringBuilder sb = new System.Text.StringBuilder();                       
  6. sb.Append(domain);
  7. sb.Apend("\\");
  8. sb.Append("\\");
  9. sb.Append(Name);
  11. string DomainUserName = sb.ToString();
when I tried with the follow I still gets the error-"An error was encountered while retrieving the user profile".
Error: UserProfile userProfile = profileManager.GetUserProfile(DomainUserName);

Please help me.
Feb 14 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,374
Try commenting out line 8. There should be no need to use two escaped backslashes.
Feb 14 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.