I have the function:
public SPList CreateList(SPFeatureReceiverProperties properties, Dictionary<string, List<AddParams>> columns,
string name, string description, SPListTemplateType type, string viewDescription)
{
SPList spList = null;
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
{
SPWeb web = siteCollection.RootWeb;
web.Lists.Add(name, description, type);
web.Update();
// Add the new list and the new content.
spList = web.Lists[name];
foreach(KeyValuePair<string, List<AddParams>> col in columns){
spList.Fields.Add(col.Key, col.Value[0].type, col.Value[0].required);
}
spList.Update();
//Create the view? - Possibly remove me.
System.Collections.Specialized.StringCollection stringCollection =
new System.Collections.Specialized.StringCollection();
foreach (KeyValuePair<string, List<AddParams>> col in columns)
{
stringCollection.Add(col.Key);
}
//Add the list.
spList.Views.Add(viewDescription, stringCollection, @"", 100,
true, true, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, false);
spList.Update();
return spList;
}
return spList;
}
Yet for some reason when debugging the siteCollection is coming back null which is causing it to not do what I want it to. When I inspect properties.Feature.Parent
I see the site Name: 'Team Site'
So why is this null?
Update:
This project, is site scoped
Because it is not a kind of SPSite? So when you cast it as something it's not it becomes null?