【问题标题】:SharePoint 2007: AfterProperties of person input field shows always -1 as lookupidSharePoint 2007:人员输入字段的 AfterProperties 始终显示 -1 作为lookupid
【发布时间】:2010-07-29 22:56:55
【问题描述】:

我正在为 SharePoint 2007 AfterProperties 苦苦挣扎。我有一个人员输入字段,可以在其中添加几个人。

在 ItemUpdating 事件中,我现在需要确定哪些用户被添加、删除或保持不变。

不幸的是,这变得很困难,因为未触及用户的 id 在 AfterProperties 中变为 -1,因此我无法使用 SPFieldUserValueCollection 来查找用户。

一个例子。 properties.ListItem["AssignedTo"].ToString() 显示:

1;#domain\user1;#2;#domain\user2

properties.AfterProperties["AssignedTo"].ToString() 显示:

-1;#domain\user1;#-1;#domain\user2;#3;#domain\user3

我计划使用以下代码来确定删除和添加的用户:

foreach (SPFieldUserValue oldUser in oldUserCollection)
{
   if (newUserCollection.Find(x => x.LookupId == oldUser.LookupId) == null)
   {
      RemoveRole(aListItem, oldUser.User, roleDefCollection[workerRoleName]);
   }
}

foreach (SPFieldUserValue newUser in newUserCollection)
{
   if(oldUserCollection.Find(x => x.User.LoginName == newUser.LookupValue) == null)
   {
      AddRole(aListItem, newUser.User, roleDefCollection[workerRoleName]);
   }
} 

我如何归档,AfterProperties 显示正确的查找 ID?

【问题讨论】:

    标签: sharepoint input userid


    【解决方案1】:

    自己解决了这个问题。我现在不使用 SPFieldUserCollection,而是使用列表并尝试自己从字符串中解析所有信息。

    Regex reg = new Regex(@"\;\#");
    string[] usernameParts = reg.Split(usernames);
    List<SPUser> list = new List<SPUser>();
    int id;
    
    foreach (string s in usernameParts)
        {
            if (!string.IsNullOrEmpty(s))
            {
                if (!Int32.TryParse(s, out id))
                {
                    if (list.Find(x => x.ID == spweb.Users[s].ID) == null)
                        list.Add(spweb.Users[s]);
                }
                else
                {
                    if (Convert.ToInt32(s) != -1)
                    {
                        if (list.Find(x => x.ID == Convert.ToInt32(s)) == null)
                            list.Add(spweb.Users.GetByID(Convert.ToInt32(s)));
                    }
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 2011-06-12
      相关资源
      最近更新 更多