Creating SharePoint 2007 List with ListInstance if ListTemplate is defined in other feature
If you are creating both ListTemplate and ListInstance in the same feature, then there is no problems and its Element Manifest could be something like:
<ListTemplate
Name="LDContacts"
DisplayName="Contacts"
Type="14001"
Description=""
BaseType="0"
OnQuickLaunch="FALSE"
SecurityBits="11"
Hidden="FALSE"
RootWebOnly="FALSE"
/>
<ListInstance
Id="14001"
Title="Contacts"
OnQuickLaunch="FALSE"
TemplateType="14001"
Url="Lists/Contacts"
RootWebOnly="FALSE"
/>
If you requirements is that you are defining ListTemplate in Site scoped feature and you need to define ListInstance in Web scoped feature. If you will try to divide this XML sections into to XML files and activate this feature you will see error message.
If you will explore SharePoint log files you can find following error description:
Feature Activation: Threw an exception, attempting to
roll back. Feature 'FeatureName' (ID:
'55266e29-72ba-4771-947f-5550d53e7b75'). Exception:
Microsoft.SharePoint.SPException: Cannot complete this
action. Please try again. --->
System.Runtime.InteropServices.COMException
(0x81072101): Cannot complete this action. Please try
again. at
Microsoft.SharePoint.Library.SPRequestInternalClass.CreateList(String
bstrWebUrl, String bstrTitle, String bstrDescription,
String bstrListUrl, String bstrFeatureId, Int32
lTemplateID, String bstrDocTemplateType,
ListQuickLaunchOptions qlOpt) at
Microsoft.SharePoint.Library.SPRequest.CreateList(String
bstrWebUrl, String bstrTitle, String bstrDescription,
String bstrListUrl, String bstrFeatureId, Int32
lTemplateID, String bstrDocTemplateType,
ListQuickLaunchOptions qlOpt) --- End of inner
exception stack trace --- at
Microsoft.SharePoint.Library.SPRequest.CreateList(String
bstrWebUrl, String bstrTitle, String bstrDescription,
String bstrListUrl, String bstrFeatureId, Int32
lTemplateID, String bstrDocTemplateType,
ListQuickLaunchOptions qlOpt) at
Microsoft.SharePoint.SPListCollection.CreateList(String
strTitle, String strDescription, String strListUrl,
String strFeatureId, Int32 templateID, String
strDocTemplateType, QuickLaunchOptions qlOpt) at
Microsoft.SharePoint.SPListCollection.Add(String
strTitle, String strDescription, String strUrl, String
strFeatureId, Int32 templateType, String
docTemplateType, QuickLaunchOptions
quickLaunchOptions) at
Microsoft.SharePoint.SPListInstanceElement.EnsureListExists(SPWeb
web) at
Microsoft.SharePoint.SPListInstanceElement.ElementActivated(SPFeaturePropertyCollection
props, SPSqlCommand sqlcmdAppendOnly, SPWebApplication
webApp, SPSite site, SPWeb web, Boolean fForce) at
Microsoft.SharePoint.Administration.SPElementDefinitionCollection.
ProvisionListInstances(SPFeaturePropertyCollection
props, SPSite site, SPWeb web, Boolean fForce) at
Microsoft.SharePoint.Administration.SPElementDefinitionCollection.
ProvisionElements(SPFeaturePropertyCollection
props, SPWebApplication webapp, SPSite site, SPWeb web,
Boolean fForce) at
Microsoft.SharePoint.SPFeature.ProvisionElements(SPFeaturePropertyCollection
props, SPWebApplication webapp, SPSite site, SPWeb web,
Boolean fForce) at
Microsoft.SharePoint.SPFeature.Activate(SPSite
siteParent, SPWeb webParent, SPFeaturePropertyCollection
props, Boolean fForce)
To resolve this issue you should define in ListInstance element FeatureId where is defined ListTemplate. Now ListInstance block can be like:
<ListInstance
Id="14001"
Title="Contacts"
OnQuickLaunch="FALSE"
TemplateType="14001"
Url="Lists/Contacts"
RootWebOnly="FALSE"
FeatureId="5F119914-D14F-4147-A3C7-AF6E6AD2E2D4"
/>
Now feature should be activated successfully.