开发者

SPListTemplate not found via Event Receiver in SharePoint 2007

开发者 https://www.devze.com 2023-02-19 03:47 出处:网络
I have a custom site template which activates a feature with an event receiver, the only thing that receiver does is to activate some other features, all in the same receiver.

I have a custom site template which activates a feature with an event receiver, the only thing that receiver does is to activate some other features, all in the same receiver.

The first feature I activate is a ListTemplate called "Audits". In the third feature I activate, I try to use that template via the object model, however it isn't found, so it throws an exception.

I tried to update the site with a web.Update() but that didn´t work either.

The code doesn´t work when its activated via the site template, that means, if I activate my feature from an already created site, it works fine.

Is there a way to access the ListTemplate when the site is created¿?

Thanks in advance

EDIT: This is the main feature

/// <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);

    }

The first feature is the list template. The thir开发者_运维百科d feature has a receiver in which i look for the template

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

However, I get an Index out of range exception, because it's not found. As I said, it only happens when the main feature is activated via the site template in the Feature tag. If I create a Blank site and then activate the main feature, everything works.

Thanks


Your site is probably not fully provisioned at the time your feature receiver is fired. This means not all site elements (e.g. the list templates) are available. As a workaround you could implement a provisioning provider.

The SPWebProvisioningProvider lets you take control of the SPWeb (Web site) or SPSite (Site Collection) that your are provisioning. Instead of just using a Site Template and the changes that can be applied through a Site Template you can add your own custom code to the solution.

from The mystery that is SPWebProvisioningProvider.

0

精彩评论

暂无评论...
验证码 换一张
取 消