可以结合XML来进行自动添加1、添加 User PropertiesUrl:http://msdn.microsoft.com/zh-cn/library/ms519896.aspx //Code example adds a new property called Marital Status.
using (SPSite site = new SPSite("http://servername"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);
try
{
ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
// create core property
CorePropertyManager cpm = ppm.GetCoreProperties();
CoreProperty cp = cpm.Create(false);
cp.Name = "MaritalStatus";
cp.DisplayName = "Marital Status";
cp.Type = PropertyDataType.StringSingleValue;
cp.Length = 100;
cpm.Add(cp);
// create profile type property
ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
ProfileTypeProperty ptp = ptpm.Create(cp);
ptpm.Add(ptp);
// create profile subtype property
ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
ProfileSubtypePropertyManager pspm = ps.Properties;
ProfileSubtypeProperty psp = pspm.Create(ptp);
psp.PrivacyPolicy = PrivacyPolicy.OptIn;
psp.DefaultPrivacy = Privacy.Organization;
pspm.Add(psp);
}
catch (DuplicateEntryException e)
{
Console.WriteLine(e.Message);
Console.Read();
}
catch (System.Exception e2)
{
Console.WriteLine(e2.Message);
Console.Read();
}
} 2、添加 UserProfile Mappingusing (SPSite site = new SPSite("http://localhost"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
//Initialize user profile config manager object.
UserProfileConfigManager upcm = new UserProfileConfigManager(context);
ConnectionManager cm = upcm.ConnectionManager;
Connection connection = cm["ADConnection"];
PropertyMapCollection pmc = connection.PropertyMapping;
pmc.AddNewMapping(ProfileType.User, "Title", "givenName");
}