如何:为用户配置文件属性设置隐私策略
上次修改时间: 2010年3月23日
适用范围: SharePoint Server 2010
利用 Microsoft SharePoint Server 2010,您可以对用户配置文件属性、成员资格、同事和类似内容设置隐私策略,以限制可以查看和编辑个人信息的人员。
默认隐私策略限制属性、用户的"我的文档"和其他"我的网站"内容对以下各项的可见性:
专用 [只有我]
经理 [我和我的经理]
我的工作组 [组织]
我的同事 [联系人]
公共 [任何人]
隐私策略指定为属性提供值为强制、禁用还是可选。隐私策略仅适用于用户配置文件属性。
下面的代码示例介绍如何设置属性的隐私。运行代码示例前,请将 servername 和 Hobbies 替换为实际值。此外,请在您的 Microsoft Visual Studio 项目中添加对以下内容的引用:
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
Microsoft.SharePoint
System.Web
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"))
{
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();
}
}
}
}