Link to home
Start Free TrialLog in
Avatar of maaknplan
maaknplanFlag for South Africa

asked on

MS SharePoint 2010 - Using Object Model to read user profile property privacy.

I am using the SP object model to query the user profile to render the contents in a custom web part. Retrieving the value stored in each property is simple enough, however I seem to be unable to retrieve the Privacy setting on the property as set by the user under the "Show To" column in "Edit My Profile".

The code below demonstrates how to manipulate the DefaultPrivacy, but I am after the "ActualPrivacy" that the user set, the "ActualPrivacy" overrides the "DefaultPrivacy"

 
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;

namespace UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {

            using (SPSite site = new SPSite("http://servername"))
            {
                SPServiceContext context = SPServiceContext.GetContext(site);
 
                ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                ProfileSubtypePropertyManager pspm = ps.Properties;
                ProfileSubtypeProperty p = pspm.GetPropertyByName("Hobbies");
                p.DefaultPrivacy = Privacy.Manager;
                p.PrivacyPolicy = PrivacyPolicy.OptIn;
                p.Commit();

            }
        }
    }
}

Open in new window


Any help much appreciated.
ASKER CERTIFIED SOLUTION
Avatar of maaknplan
maaknplan
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial