Updating the count for a field in userprofile through code in sharepoint 2010
-
Friday, June 08, 2012 6:23 AM
Hi,
Iam using a field called 'click through count'.
My requirement is that when click through count gets past 4 clicks,button shouldnot be displayed.
I need to update each click into the userprofile field click through count.
How can i do it?
Thanks in advance for replies..
All Replies
-
Monday, June 11, 2012 7:03 PM
The following code uses the server object model to update a user's profile property.
public static void SetProfileProperty() { SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default); UserProfileManager upm = new UserProfileManager(context, true); UserProfile up = upm.GetUserProfile("basesmc2008\\testsp2010"); up["Scanner"].Value = "ScanSnap1"; up.Commit(); }Blog | SharePoint Field Notes Dev Tool | ClassMaster
- Proposed As Answer by Bjoern H RappMicrosoft Community Contributor, Moderator Monday, June 11, 2012 7:38 PM
- Marked As Answer by Shimin Huang Friday, June 15, 2012 2:42 AM
-
Thursday, June 14, 2012 6:12 AM
Thanks for the reply...
Iam not able to update the user profile values while using an application page.Is there any issue while uisng an aplication page to update user profile?
-
Thursday, June 14, 2012 2:36 PM
What error are you receiving? If the code is trying to update a user profile that is not the user profile of the currently logged in user, then the user currently logged on must have "Managed User Profiles" permission. You can give this permission by going to Central Administratrion --> Managed Service Applications --> select the user profile service application and click the Permissions button. You can add the permission in this dialog. Elevating permissions will not have any effect, the internal code uses the logged in user.Blog | SharePoint Field Notes Dev Tool | ClassMaster
- Marked As Answer by Shimin Huang Friday, June 15, 2012 2:42 AM
-
Thursday, June 14, 2012 3:40 PM
hi girish
use code bellow for update user profile:
SPListItem currentUserItem = SPContext.Current.Web.SiteUserInfoList.GetItemById(SPContext.Current.Web.CurrentUser.ID); currentUserItem["click through count"] = int.Parse(currentUserItem["click through count"] as string) + 1;and for your button, use Code like bellow:
if (int.Parse(SPContext.Current.Web.SiteUserInfoList.GetItemById(SPContext.Current.Web.CurrentUser.ID)["click through count"] as string) > 4) button1.Visible = false;
yaşamak bir eylemdir
- Marked As Answer by Shimin Huang Friday, June 15, 2012 2:42 AM

