SharePoint determines whether the user is in the field & quot; personnel and Group & quot;. The sharepoint Field

Source: Internet
Author: User

SharePoint determines whether the user is in the field "personnel and group", sharepoint Field

These two methods are recorded for future use;

1. Determine whether the user is in the field personnel and group;

    public static bool IsUserInFiled(int UserID, string ListName, int ItemID, string FieldInterName)        {            bool value = false;            try            {                using (SPSite site = new SPSite(SITERUL))                {                    using (SPWeb web = site.OpenWeb())                    {                        SPList list = web.Lists.TryGetList(ListName);                        SPListItem item = list.GetItemById(ItemID);                        string dispName = list.Fields.GetFieldByInternalName(FieldInterName).Title;                        SPFieldUserValueCollection uu = new SPFieldUserValueCollection(web, item[dispName].ToString());                        foreach (SPFieldUserValue u in uu)                        {                            if (u.User != null)                            {                                if (UserID == u.User.ID)                                    value = true;                            }                            else                            {                                string userStr = u.ToString().Split(';')[0];                                int groupID = Convert.ToInt32(userStr);                                SPGroup group = web.SiteGroups.GetByID(groupID);                                foreach (SPUser user in group.Users)                                {                                    if (UserID == user.ID)                                        value = true;                                }                            }                        }                    }                }            }            catch { }            return value;        }

2. Getting Menu menus is a little tricky;

    public static string GetMenu(string ListName)        {            string menuHtml = string.Empty;            using (SPSite site = new SPSite(SITEURL))            {                using (SPWeb web = site.OpenWeb())                {                    SPList list = web.Lists.TryGetList(ListName);                    SPQuery query = new SPQuery();                    query.Query = "";                    SPListItemCollection itemcoll = list.GetItems(query);                    foreach (SPListItem item in itemcoll)                    {                        string Title = list.Fields.GetFieldByInternalName("Title").Title;                        string Link = list.Fields.GetFieldByInternalName("Link").Title;                        string IsShow = list.Fields.GetFieldByInternalName("IsShow").Title;                        string IsOpenNewPage = list.Fields.GetFieldByInternalName("IsShow").Title;                        menuHtml += item[Title].ToString();                    }                }            }            return menuHtml;        }

Secondary note

For personal record only. If necessary, debug it first;




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.