
Received an assignment to create a view page for mysite profile, one of the challenge is to get the checkboxlist value from database.
Found this (http://madalina.blog.com/2011/02/09/sharepoint-2010-programmatically-change-activities-that-i-follow/) from google search result.
Article above saved my time to get a list of data from “Activity That I m Following” but to get the checkboxlist value of “Activity That I m Following” seem not very straight forward.
2 API you need to pay attention in order to get those checkboxlist value, which are ActivityManager and ActivityPreferencePerType
Here some snippet code to retrieve the checkboxlist value, as for updating the value, you may refer the above URL for more information.
SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager uprofileManager = new UserProfileManager(context);
if (uprofileManager.UserExists(GetDecodedAccountName(hAcctName.Value)))
{
UserProfile up = uprofileManager.GetUserProfile(GetDecodedAccountName(hAcctName.Value));
ActivityManager activityManager = new ActivityManager(up, context);
List<activitypreferencepertype> activityPrefsPerTypes = activityManager.ActivityPreferences.GetActivityPreferencesPerType();
foreach (ActivityPreferencePerType ab in activityPrefsPerTypes)
{
foreach (ActivityType a in activityManager.ActivityTypes)
{
if (ab.ActivityType.Equals(a))
{
if (!a.ActivityTypeName.ToLower().Contains("internal_"))
{
string source = String.Concat("$Resources:", a.ActivityTypeNameLocStringName);
string resourceFile = a.ActivityTypeNameLocStringResourceFile;
string displayName = SPUtility.GetLocalizedString(source, resourceFile, SPContext.Current.Web.Language);
lblActivity.Text += string.Format("<input type=\"checkbox\" {0} disabled=\"disabled\" />" + displayName + "<br />", ab.IsSet ? Constants.YES : Constants.NO);
}
}
}
}
}
Enjoy.
Incoming search terms:
Like this:
Like Loading...