SharePoint 2010 C# 获取People Or Group

SharePoint 2010 C# 获取People Or Group

 

 

public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            bool judge = false;
            SPListItem item = properties.ListItem;
            SPFieldUserValueCollection FieldUserValueCollection = (SPFieldUserValueCollection)item["Users"];
            SPFieldUserValueCollection fieldUserValues = new SPFieldUserValueCollection();
            if (FieldUserValueCollection != null)
            {
                foreach (SPFieldUserValue FieldUserValue in FieldUserValueCollection)
                {
                    if (FieldUserValue.User != null)
                    {
                        if (FieldUserValue.User.ID == SPContext.Current.Web.CurrentUser.ID)
                        {
                            judge = true;
                            break;
                        }
                    }
                    //if the field contain group
                    else
                    {
                        SPGroup group = SPContext.Current.Web.SiteGroups.GetByID(FieldUserValue.LookupId);
                        SPUser currentUser = SPContext.Current.Web.CurrentUser;
                        SPGroupCollection userGroups = currentUser.Groups;
                        foreach (SPGroup mygroup in userGroups)
                        {
                            if (group.Name == mygroup.Name)
                                judge = true;
                            break;
                        }
                    }

                }

                if (judge == true)
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "You cannot delete the file.";
                }

            }

        }

 

posted @ 2013-05-28 16:10  山之子  阅读(290)  评论(0编辑  收藏  举报