0
votes

I have a Sharepoint feature that includes a settings list template, which is read by other features. The list must have a particular name for the whole thing to work, so ideally I would rather have a list created instead of a list template.

I tried playing with the EventReceiver class, by overriding FeatureInstalled method. It receives a parameter of SPFeatureReceiverProperties type. I've looked through documentation, and saw that one property, UserCodeSite, refers to the SPSite where the feature is installed, if it is a Site scoped solution, which it is in my case. That way I wanted to write a piece of code that would create a specific list from the list template included in the feature.

SPWeb_object.Lists.Add(listName, "", SPListTemplate_object)

However the property is null, as well as the Feature property. So I can't get the SPSite object, and I can't get the SPWeb object.

Any other ideas?

2
so, in your Sharepoint project are you having the List created upon implementation? - haydnD
I want to have that. And it would be preferable to have that list created from a template. So far I only have the template. - Alex

2 Answers

2
votes

You can create a new list instance ListInstance construct. See this: http://msdn.microsoft.com/en-us/library/ms476062.aspx The list will be created upon activating that particular feature. For automatic activation of a feature you can use feature stapling. See this http://msdn.microsoft.com/en-us/library/ff648422.aspx

1
votes

List creation is a very common requirement. It's often best to create a list instance upon activation rather than installation, as suggested by another poster. You can access the desired activation scope (the SPWeb or SPSite in which the feature is activated) like so:

SPWeb web = (SPWeb)properties.Feature.Parent;

or

SPSite site = (SPSite)properties.Feature.Parent;

Hope this helps.