2

In sitecore:

If a user is logged in with user name "Addemo", How Can I get the User profile item which is under /sitecore/content/Intranet/User Profiles/A/Ad/addemo.

I tried with User.Current.Profile.ProfileItemId; But the ID I get with this is not the item Id of addemo (/User Profiles/A/Ad/addemo).

2
  • What product are you using for your Intranet? The profile path you are expecting, is not one of Sitecores security profile locations. Sep 23, 2015 at 10:33
  • I am using Sitecore Intranet
    – Kamran
    Sep 23, 2015 at 11:47

2 Answers 2

5

It looks like you are using Sitecore Intranet. I'm not 100% familiar with the details of that (mostly my coworkers that work with that part), but this should be what you are looking for:

using Sitecore.Intranet.Profiles;
using Sitecore.Intranet.Profiles.Providers;
using Sitecore.Security.Accounts; 

// ------------------------------

var userName = User.Current.Name;
var account = Account.FromName(userName, AccountType.User);

var profileProvider = new UserProfileProvider(new Settings());
var profile = profileProvider.GetProfile(account.LocalName.ToLower());

var profileItem = profile.ProfileItem;

I haven't tested this as I don't have a solution at hand, so let me know if something is a bit off.

1
  • Yes I have tested your code and its working. Thanks!!
    – Kamran
    Sep 23, 2015 at 11:58
-1

Sitecore.Context.User has a Profile property, so right you are. You may retrieve custom profile values through GetCustomProperty() method, like that:

string resetValue = Sitecore.Context.User.Profile.GetCustomProperty("Has Password Reset");

or set custom values:

Sitecore.Context.User.Profile.SetCustomProperty("Has Password Reset", "1");

The profile itself should be somewhere under /sitecore/templates/System/Security node. If you want to edit custom profile values for a particular user from UI, you can do that from Sitecore: User Manager --> (click a user) --> Profile tab --> Additional Properties (below)

More to read about:

http://blog.horizontalintegration.com/2014/04/07/sitecore-custom-user-profile-properties/

https://www.markstiles.net/Blog/2013/09/05/Sitecore-Custom-User-Properties.aspx

https://briancaos.wordpress.com/2014/06/12/sitecore-users-custom-profile-properties/

Your Answer

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

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