代码之家  ›  专栏  ›  技术社区  ›  yan.kun

SharePoint2007:AfterProperties of Person输入字段始终将-1显示为LookupID

  •  0
  • yan.kun  · 技术社区  · 16 年前

    我正在努力处理SharePoint2007 AfterProperties。我有一个人员输入字段,可以在其中添加几个人员。

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

    不幸的是,由于未受影响的用户的ID在AfterProperties中变为-1,所以我无法使用SPFieldUserValueCollection查找用户。

    一个例子。properties.listem[“assignedto”].toString()显示:

    1;域\用户1;2;域\用户2

    properties.afterproperties[“assignedto”].toString()显示:

    -1;域\用户1;-1;域\用户2;3;域\用户3<-添加用户

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

    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显示正确的lookupID?

    1 回复  |  直到 16 年前
        1
  •  0
  •   yan.kun    16 年前

    自己解决了这个问题。我现在使用的不是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)));
                    }
                }
            }
        }