У меня есть функция:Почему SiteCollection всегда имеет значение null?
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 возвращается нуль, который является причиной этого не делать то, что я от него хочу. Когда я проверяю properties.Feature.Parent
, я вижу сайт Имя: 'Team Site'
Так почему же этот нуль?
Update:
Этот проект является сайт области видимости
Может быть полезно добавить информацию о том, кто и с какого приложения вызывает этот метод ... –