Thursday, 13 March 2014

get all lookup value from sharepoint customlist using c#

Share it Please
 List<string> myCollection = new List<string>();
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists[ListName];
                        int i = 0;
                        foreach (SPListItem item in list.Items)
                        {
                            SPListItem spitem = list.Items[i];
                            SPFieldLookupValue group = new SPFieldLookupValue(spitem[LookupColumnName].ToString());
                            string lookedUpItemTitle = group.LookupValue;
                            myCollection.Add(lookedUpItemTitle);
                            i++;
                        }
                    }
                }
            });

No comments:

Post a Comment

Followers

Follow The Author