【问题标题】:SPListTemplate not found via Event Receiver in SharePoint 2007在 SharePoint 2007 中未通过事件接收器找到 SPListTemplate
【发布时间】:2011-03-23 16:07:23
【问题描述】:

我有一个自定义站点模板,它通过事件接收器激活一个功能,接收器唯一要做的就是激活一些其他功能,所有这些都在同一个接收器中。

我激活的第一个功能是一个名为“Audits”的 ListTemplate。 在我激活的第三个功能中,我尝试通过对象模型使用该模板,但未找到,因此引发异常。

我尝试使用web.Update() 更新网站,但这也不起作用。

代码在通过站点模板激活时不起作用,这意味着,如果我从已创建的站点激活我的功能,它可以正常工作。

有没有办法在网站创建时访问 ListTemplate?

提前致谢

编辑:这是主要功能

/// <summary>
    /// Evento disparado al activar la feature
    /// </summary>
    /// <param name="properties"></param>
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        //Obteniendo el sitio (web) en donde fue activada la feature
        SPWeb web = (SPWeb)properties.Feature.Parent;

        //Guid a utilizar para instalar las features
        Guid g;

        //GUID de Feature de list template de auditorías
        g = new Guid("{3b91e461-e8c9-49dd-857a-671eb031017c}");
        if (web.Features[g] == null)
            web.Features.Add(g);

        //GUID de Feature Catalogos
        g = new Guid("{d102dd61-0aaf-4a18-8bcc-2260e78cc87c}");            
        if (web.Features[g] == null) 
            web.Features.Add(g);

        //GUID de Feature Content type de auditorías
        g = new Guid("{a5c3defb-bcbf-41e5-aefc-2617814d25d6}");
        if (web.Features[g] == null) 
        web.Features.Add(g);

        //GUID de Feature CheckList template
        g = new Guid("{63fa11ba-e8e2-414d-bb7e-a3cdbce11cfe}");
        if (web.Features[g] == null) 
        web.Features.Add(g);

        //GUID de Feature asocia eventos
        g = new Guid("{bbc32500-034d-4d9e-a048-558d62edfe53}");
        if (web.Features[g] == null)
            web.Features.Add(g);

        //GUID de Feature para crear preguntas
        g = new Guid("{ee66eb41-57a4-400a-9c50-8db0e6beeb80}");
        if (web.Features[g] == null) 
        web.Features.Add(g);

        //GUID de Feature para ECB
        g = new Guid("{9bbdb06c-4ea1-4328-8b3d-828ea2043d3e}");
        if (web.Features[g] == null) 
        web.Features.Add(g);

        //GUID de Feature para hallazgos
        g = new Guid("{acfdda27-58d5-4f7e-a6de-0a7fe190bc74}");
        if (web.Features[g] == null)
            web.Features.Add(g);

        //GUID de Feature para resultados
        g = new Guid("{a9a804dd-18a3-47a0-80bf-25e785a8cac8}");
        if (web.Features[g] == null)
            web.Features.Add(g);

    }

第一个功能是列表模板。 第三个功能有一个接收器,我在其中寻找模板

//Obteniendo el template
        SPListTemplate ltAuditorias = sitio.ListTemplates["Auditoria"];

但是,我得到一个索引超出范围异常,因为它没有找到。 正如我所说,只有在通过 Feature 标签中的站点模板激活主要功能时才会发生这种情况。 如果我创建一个空白网站,然后激活主要功能,一切正常。

谢谢

【问题讨论】:

  • 您可能需要发布一些代码让我们更好地了解您在做什么。

标签: sharepoint sharepoint-2007


【解决方案1】:

在您的功能接收器被触发时,您的网站可能尚未完全配置。这意味着并非所有站点元素(例如列表模板)都可用。 作为一种解决方法,您可以实现 provisioning provider

SPWebProvisioningProvider 让您可以控制您正在配置的 SPWeb(网站)或 SPSite(网站集)。您可以将自己的自定义代码添加到解决方案中,而不仅仅是使用站点模板和可以通过站点模板应用的更改。

来自The mystery that is SPWebProvisioningProvider

【讨论】:

    猜你喜欢
    • 2012-11-14
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    相关资源
    最近更新 更多