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:
- 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)
- somehow manipulate the document library template to include the lookup fields