2

I would like to know how to get the Property Privacy settings when the user changed from "MY Manager" to "My colleague" in edit profile page ?

I am able to get the Default privacy value, but i want user-specific Privacy settings value for specific property.. ? How can i achieve this ?

  • could you say what approach you have in mind (programmatically - event handling, powershell,etc.) ? – Supriyo SB Chatterjee Apr 16 '12 at 20:30
2

I got this using SharePoint API. Find the following code.

        string privacyvalue = string.Empty;
        SPUser AdminUser = SPContext.Current.Web.AllUsers[@"SHAREPOINT\SYSTEM"];
        var superToken = AdminUser.UserToken;
        HttpContext con = HttpContext.Current;
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.Url, superToken))
            {
                SPServiceContext context1 = SPServiceContext.GetContext(site);
                HttpContext.Current = null;
                UserProfileManager upm = new UserProfileManager(context1, false);
                this.userProfile = upm.GetUserProfile(this.UserAccount);
                Privacy privacy = this.userProfile[PropertyName].Privacy;
                privacyvalue = privacy.ToString();
             }  
         });
       HttpContext.Current = con;
  • 1
    to get the systemaccount you should just use SPContext.Current.Site.SystemAccount and also if you want to update or commit the userprofile you should use System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted); ps.Assert(); – Jalali Shakib Jun 30 '12 at 4:32
  • Can you please mark this as your answer (to put the question in correct state)? :) – Robert Lindgren Jan 15 '14 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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