0

This is what I have so far. It seems to work, but is very slow since its traversing all lists and fields in the site. Note: I am looking for the first list that shows up as a 'child list':

private SPList GetChildList(SPList list)
    {
        SPList childList = null;

        using (SPSite spSite = new SPSite("http://dev01/"))
        {
            using (SPWeb spWeb = spSite.RootWeb)
            {
                foreach (SPList relatedList in spWeb.Lists)
                {
                    foreach (SPField field in relatedList.Fields)
                    {
                        if (field.Type == SPFieldType.Lookup && field.InternalName.Contains("SomeFieldName"))
                        {
                            SPFieldLookup lookupField = field as SPFieldLookup;
                            if (list.RootFolder.Name == spWeb.Lists[new Guid(lookupField.LookupList)].RootFolder.Name)
                            {
                                return relatedList;
                            }
                        }
                    }
                }
            }
        }

        return childList;
    }
0

Perhaps you could iterate through site fields, instead of lists, and foreach LookupField check its ListsFieldUsedIn method.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.listsfieldusedin.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.