public static SPFieldLookupValueCollection GetLookFieldIDS(string lookupValues, SPList lookupSourceList) { SPFieldLookupValueCollection lookupIds = new SPFieldLookupValueCollection(); string[] lookups = lookupValues.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string lookupValue in lookups) { SPQuery query = new Microsoft.SharePoint.SPQuery(); query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", lookupValue); SPListItemCollection listItems = lookupSourceList.GetItems(query); foreach (Microsoft.SharePoint.SPListItem item in listItems) { SPFieldLookupValue value = new SPFieldLookupValue(item.ID.ToString()); lookupIds.Add(value); break; } } return lookupIds; }
public static SPFieldLookupValueCollection GetLookFieldIDS(string lookupValues, SPList lookupSourceList) { SPFieldLookupValueCollection lookupIds = new SPFieldLookupValueCollection(); string[] lookups = lookupValues.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string lookupValue in lookups) { SPQuery query = new Microsoft.SharePoint.SPQuery(); query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", lookupValue); SPListItemCollection listItems = lookupSourceList.GetItems(query); foreach (Microsoft.SharePoint.SPListItem item in listItems) { SPFieldLookupValue value = new SPFieldLookupValue(item.ID.ToString()); lookupIds.Add(value); break; } } return(lookupIds); }