首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么SiteCollection总是空的?

为什么SiteCollection总是空的?
EN

Stack Overflow用户
提问于 2013-06-06 18:36:26
回答 4查看 1K关注 0票数 0

我的职责是:

代码语言:javascript
复制
    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时,我看到了网站名称:“Team”

那么为什么这个值为空呢?

更新:

此项目是站点范围内的。

EN

回答 4

Stack Overflow用户

发布于 2013-06-06 18:40:19

在行实例化运行后,siteCollection可能是null的原因有两个:

  1. properties.Feature.Parentnull
  2. properties.Feature.Parent不是SPSite (或派生自SPSite)

如果您说在调试器中可以看到properties.Feature.Parent不是null,而siteCollection是,那就意味着properties.Feature.Parent不是SPSite实例。

通过打开“监视”窗口并输入表达式properties.Feature.Parent.GetType(),可以在调试时看到此属性的类型。

票数 1
EN

Stack Overflow用户

发布于 2013-06-06 18:39:03

因为它不是一种SPSite?所以当你把它当作某物的时候,它不是空的吗?

票数 0
EN

Stack Overflow用户

发布于 2013-06-06 18:39:50

也许properties.Feature.Parent不是SPSite对象。代码as SPSitesiteCollection设置为Null,如果它是SPWeb对象

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16969619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档