使用 c# 从 Sharepoint 2010 用户配置文件中删除值

Delete values from Sharepoint 2010 user profile using c#

我可以在 Sharepoint 用户配置文件中添加和编辑值。但我无法从 UP 中删除值。例如,我已将用户配置文件 属性 添加为 "Certifications" 我可以使用 C# 代码将值添加到 UP 中。我想使用 C# 代码从用户配置文件中删除值。

我在我的环境中做了一些测试,这个有效:

using (SPSite site = new SPSite("http://xxx/"))
{
    using (SPWeb web = site.OpenWeb())
    {
       try
       {
           SPServiceContext serviceContext = SPServiceContext.GetContext(site);
           UserProfileManager userProfileManager = new UserProfileManager(serviceContext);
           UserProfile userprofile = userProfileManager.GetUserProfile("your login");
           //Set value
           userprofile["Department"].Value = "Whosebug";
           userprofile.Commit();
           //Remove value
           userprofile["Department"].Value = "";
           userprofile.Commit();
      }
      catch (Exception ex)
      {
          //TO DO
      }
   }
}

如果您向我们提供更多信息,我可以编辑我的代码以获得更详细的示例。