I'm trying to build a form that will copy values from one field to another for a set of user's profiles. I have checked that all users have the same profile assigned (by checking the profile ID with user.Profile.ProfileItemId and I also checked the same thing in the User Manager tool, for some of the users).
Before moving a value from one field to another I want to check that the inputted field names actually exist for the current user's profile, so I'm calling GetCustomPropertyNames for each user's profile and checking whether the field name is present in the list of field names returned by the method.
I have noticed that for some users not all of the field names are returned. The missing fields are listed in the User Details dialog box with no value (empty fields). Adding values for fields not listed or clearing fields that are listed does not seem to alter the result of the GetCustomPropertyNames method.
Is there any special command that must be executed beforehand, or are there any special conditions that must be met in order to determine the method to return the entire set of available field names?
0
votes
Did you try to see if the fields are in Sitecore.Context.User.Profile.GetPropertyValue("property")?
– xoail
@xoail I'm not working with the context user, but iterating over a set of users belonging to a particular domain. However, I have tried your suggested method and for the users that have issues with GetCustomPropertyNames it raises a PropertyNotFound exception. However, I have tried it for custom fields that are returned by GetCustomPropertyNames and I get the same result. It seems to only return values for properties of the UserProfile class.
– Bogdan
Take a look at this article (sitecore.net/Community/Technical-Blogs/Getting-to-Know-Sitecore/…) if you have not already. It talk about working with sitecore client but it helped in troubleshooting a similar issue.
– xoail
1 Answers
0
votes
can you try to do it like :
var userList = Sitecore.Security.Accounts.UserManager.GetUsers();
foreach (Sitecore.Security.Accounts.User user in userList)
{
Sitecore.Security.UserProfile profile = user.Profile;
string whatever = profile["Field Name"];
}
The ASP.NET profile is used to store and retrieve user settings in a data source such as a database. The user profile is accessed using the Profile property of the current HttpContext. Profile information and property values are managed using a profile provider. The SqlProfileProvider (that is used default by Sitecore) is used by ASP.NET to store and retrieve profile settings for an ASP.NET application that is using a SQL Server database.