How to: Set Privacy Policies for User Profile Properties
Microsoft Office SharePoint Server 2007 enables you to set privacy policies on user profile properties, memberships, colleagues, and the like, to restrict who can view and edit personal information.
The Default Privacy policy limits the visibility of properties, users' My Documents, and other My Site content to:
Private [Only Me]
Manager [Me and my manager]
My Workgroup [Organization]
My Colleagues [Contacts]
Public [Everyone]
The Privacy Policy specifies whether providing a value for a property is mandatory, disabled, or optional. Privacy Policy is only applicable to user profile properties.
The following code example shows you how to set the privacy of a property. Replace servername and Hobbies with actual values before running the code example. Also add references to the following in your Microsoft Visual Studio project:
Microsoft.Office.Server
Microsoft.SharePoint
System.Web
Example
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("https://servername"))
{
ServerContext context =
ServerContext.GetContext(site);
UserProfileManager profileManager = new
UserProfileManager(context);
PropertyCollection pc = profileManager.Properties;
Property property = pc.GetPropertyByName("Hobbies");
property.DefaultPrivacy = Privacy.Manager;
property.PrivacyPolicy = PrivacyPolicy.Mandatory;
property.Commit();
}
}
}
}
See Also
Tasks
How to: Create and Edit a User Profile Property
How to: Create Multivalue Properties
How to: Set Multiple Values to a Multivalue Property
How to: Change the Default Separator Character for Entering Multivalue Properties
How to: Create Properties with Choice Lists