zoukankan      html  css  js  c++  java
  • 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.";
                    }
    
                }
    
            }
  • 相关阅读:
    17.10.13
    17.10.12
    17.10.11
    17.10.10
    17.10.05
    17.10.04
    17.10.03
    17.10.02
    17.10.01
    17.9.29
  • 原文地址:https://www.cnblogs.com/ahghy/p/3103841.html
Copyright © 2011-2022 走看看