0

In Sharepoint, is there a way to programmatically add a lookup field that refers to a diffent web site?

In the user interface, when we are in a list A, and we are adding a lookup column we can only choose to get the informations from a list B on the same web site of A.
The only way I know is to create a Site column, but in this case the referred list B must be in the root site of the site collection. And this isn't a good thing in most cases.

Is there a programming trick (C#, VB or Powershell) to add a lookup field without that limits?

1

Add a event receiver on list B (list B can be in any site). On new item added / deleted, copy the list item on a list C (for example, lets say list C) residing where list A is created.

This way you can create lookup column in List A pointing to List C. On item/ updated/deleted in List B, item can be added/ updated / deleted programmatically in List C.

0

Finally I solved the problem using an overload of AddLookup method: SPFieldCollection.AddLookup In that method is possible to define a secondary web site for the lookup list: lookupWebId

public string AddLookup(
    string displayName,
    Guid lookupListId,
    Guid lookupWebId,
    bool bRequired
)

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.