2

I have features that define site content types and a document library template that uses these content types. Now, when I create a document library from the template, all the content types appear there as expected with the metadata, except for lookupfields. They have to be added manually to the library's content types after creating the library from template.

As I searched the code, there was an intended fix for this while deploying the lookupfields:

SPList MyList = currentWeb.Lists["MyListName"];
MyList.ContentTypes["MyCustomContentType"].Delete();
MyList.Update();

MyList.ContentTypes.Add(currentWeb.ContentTypes["MyCustomContentType"]);
MyList.Update();

This would work well if I had already created the document library from the template, which I haven't.

Are there any solutions for this? I'd guess:

  1. also create the document library with a feature from the template and use the existing code (which wastes the point of using a document library template at all)
  2. somehow manipulate the document library template to include the lookup fields
1
  • Are you trying to deploy the lookup list along with the current library template?
    – sssreddy
    Commented Jan 15, 2013 at 15:09

3 Answers 3

1

If you would like to update the content type when a new list is added you can implement the above code in a ListAdded event receiver. You can check if the list added is of your library template and update the content type.

Not sure if you have a specific reason to do it via object model. You can deploy the lookup field configured properly in your library template. If you are deloying the lookup list along with the your library template, you just have to split them into different feature and ensure they are activated in proper order.

0

Check out this old post from Josh Gaffey about adding declarative lookup columns you may also like to pre-populate your lookup list

1
  • This doesn't seem to help with the document library TEMPLATE issue...
    – Indrek
    Commented Feb 1, 2012 at 11:53
0

You can create site column with type lookup and use that in your created library. In this example they referred global data between two lists by creating site columns..Refer this http://sandeepnakarmi.com.np/2011/03/sharepoint-2010-lookup-relation-between-lists-in-different-sites/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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