I have a problem with ContentTypeBinding when creating a new site. I have custom site template definition where I have referenced Publishing Server Feature, so list Pages is automatically created on site. I need to bind custom content type to OOB Pages list. Do anybody know how to do that? My custom content type is deployed by feature on site collection scope.
Now I trying to do it in this way, but it's not working. In site template I referencing feature, which contains element with content type binding:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentTypeBinding ContentTypeId="GUIDOFCONTENTTYPE" ListUrl="Pages" />
</Elements>
I'm getting this error when I try to create new site:
SPContentTypeBindingElement.ElementActivated(). An error occurred binding content type '0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390045BF70D1ABCA4A5BBF576B785EB3A37D' to list '/site/Pages' on web 'http://xxx/site'. Exception '<nativehr>0x80070057</nativehr><nativestack>owssvr.dll: (unresolved symbol, module offset=0000000000034256)
at 0x000007FEE9954256 mscorwks.dll: (unresolved symbol, module offset=00000000002BF6D7)
at 0x000007FEF61FF6D7 Microsoft.SharePoint.Library.ni.dll: (unresolved symbol, module offset=00000000000DAB02)
at 0x000007FEEAD9AB02 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001A7B029)
at 0x000007FEEE8BB029 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001BDCBB1)
at 0x000007FEEEA1CBB1 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001AB76AB)
at 0x000007FEEE8F76AB Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001AB7D2A)
at 0x000007FEEE8F7D2A Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001AB6E1F)
at 0x000007FEEE8F6E1F Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001BFCB4F)
at 0x000007FEEEA3CB4F Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001BFDF52)
at 0x000007FEEEA3DF52 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=00000000025D073E)
at 0x000007FEEF41073E Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=00000000025D0DEC)
at 0x000007FEEF410DEC Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001F0BD0F)
at 0x000007FEEED4BD0F Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001F0D8A6)
at 0x000007FEEED4D8A6 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001D2B8EE)
at 0x000007FEEEB6B8EE Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001AD36D4)
at 0x000007FEEE9136D4 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001AD2F86)
at 0x000007FEEE912F86 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=00000000020D4DCD)
at 0x000007FEEEF14DCD Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=00000000022B8A80)
at 0x000007FEEF0F8A80 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000001B006B6)
at 0x000007FEEE9406B6 Microsoft.S</nativestack>'.
Have anybody some experience with that?
UPDATE:
I finded what causes my problem. It's lookup field in my content type. When I put this lookup out it works OK. But I still don't know how to resolve it.
Definition of my lookup:
<Field ID="{2FF1B484-6D70-449c-8E5C-904E4D5971E1}"
Name="PageCategory"
Group="Intranet Columns"
Type="Lookup"
DisplayName="PageCategory"
List="Lists/Categories"
ShowField="Title"
PrependId="TRUE"/>
I know, that before this field is created list Categories must exists. So my Categories list is created in web-scope feature A and this lookup field, content type + lookup field and content type binding is in another feature B. I added dependency from B to A. Both features are referenced in onet.xml. Unfortunately I've got still the some problem.
UPDATE 2:
content type definition: Parent ContentType: Article Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D)
<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D0054b32f31a8ab44cf914825f88a74e92a"
Name="PagesWithCategory"
Group="Tieto Intranet Content Types"
Description="My Content Type"
Inherits="TRUE"
Version="0">
<FieldRefs>
<FieldRef ID="{2FF1B484-6D70-449c-8E5C-904E4D5971E1}" Name="PageCategory" DisplayName="Category" Required="TRUE"/>
</FieldRefs>
</ContentType>
webfeatures part from onet.xml:
<WebFeatures>
<!-- Master Page -->
<Feature ID="4dae3485-c2e5-4c07-adcc-28a7417b6dd9" />
<Feature ID="985b3cfc-728c-4459-90d9-5d02de88857a" />
<!-- Publishing Feature -->
<Feature ID="94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" />
<!--Lists definitions + instances CONTAINS Categories list-->
<Feature ID="be3732cc-6f55-41c1-b62c-a24a43540fad" />
<!--Content type + Binding + Lookup Fields definition -->
<Feature ID="cfe7f31c-f1bf-404d-bb8b-8425938a8602" />
</WebFeatures>
UPDATE 3:
I finded that it can be resolved by feature event reciever.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb web = (SPWeb)properties.Feature.Parent)
{
string ctname = "PagesWithCategory";
SPContentType mytype = web.AvailableContentTypes[ctname];
if (web.Lists["Pages"].ContentTypes["PagesWithCategory"] == null)
{
web.Lists["Pages"].ContentTypes.Add(mytype);
web.Lists["Pages"].Update();
}
}
}
Another (declarative, probably better) solution is update field definition how Steve recomended me.