create list definition under sub site in site definition
-
10-12-2019 - |
Question
I want to Create List Definition & List Instance under particular Sub-site.It can not been seen under site Collection.
Solution 2
Accomplished with the following code in Feature Activated event receiver.
SPSite site = null;
SPWeb web = null;
site = properties.Feature.Parent as SPSite;
web = site.AllWebs["SubSite"];
SPListTemplate temp = web.ListTemplates["ListDefinition"];
Guid newg = web.Lists.Add("ListInstance", "Description", temp);
SPList newlist = web.Lists[newg];
newlist.OnQuickLaunch = true;
newlist.Update();
OTHER TIPS
Create your List Definition using a Web Scoped feature. Set the feature attributes to Hidden=True.
You can then activate your feature manually using PowerShell for that sub-site.
For further automation you can either staple your feature to specific templates (so it is automatically included in sites which uses a specific template) or reference it in the WebFeatures element in the Onet.xml of your custom site definition.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange