Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
share|improve this question
    
Are you trying to deploy the lookup list along with the current library template? –  sssreddy Jan 15 '13 at 15:09

3 Answers 3

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.

share|improve this answer

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

share|improve this answer
    
This doesn't seem to help with the document library TEMPLATE issue... –  Indrek Feb 1 '12 at 11:53

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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