我有这个功能:
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;
}
然而,由于某种原因,在调试 siteCollection 时返回 null,这导致它无法执行我想要的操作。当我检查时,properties.Feature.Parent
我看到站点名称:“团队站点”
那么为什么这个为空呢?
更新:
这个项目,是站点范围的