0

我正在努力使用 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?

4

1 回答 1

0

自己解决了问题。我现在不使用 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)));
                }
            }
        }
    }
于 2010-07-29T14:56:55.437 回答