Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

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

1 Answer 1

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;
share|improve this answer
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.Unrest‌​ricted); 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 at 7:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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