Pregunta

Cuando creo un nuevo sitio, tengo un evento de feaTureactivado de alojamiento web que me gustaría correr.La característica se activa, pero el evento de Featurseactivated no se activa.

El sitio se crea con WebTemplate que incluye la GUID de las características en el nodo WebFeatures. Desde onet.xml de mi webtemplate que especifica la característica

<WebFeatures>
   <Feature ID="e6e83174-0e6a-4fb6-a3e9-f16739a08a93" />
</WebFeatures>

Aquí está mi código de destitución:

private const string QuicklaunchHeader = "Saksmappe";

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWeb webTemp = properties.Feature.Parent as SPWeb;
    var web = webTemp.Site.RootWeb;
    var rootFolder = web.RootFolder;
    rootFolder.WelcomePage = "Pages/CaseFolder.aspx";
    rootFolder.Update();

    //Remove old custom quick launch entry
    RemoveQuickLaunchItems(QuicklaunchHeader, web);

    //Add custom quick launch entry
    var header = new SPNavigationNode(QuicklaunchHeader, 
                                       web.Navigation.Home.Url,   false);
    web.Navigation.QuickLaunch.AddAsFirst(header);

    //TODO Set correct urls
    header.Children.AddAsLast(new SPNavigationNode("Saksdetaljer", ""));
    header.Children.AddAsLast(new SPNavigationNode("Merknader", ""));
}

Cuando creo el sitio, no puedo depurar el código.He intentado el debugger.break () y poniendo un punto de interrupción en VS2010.

Cuando implemento el paquete de VS2010, el código Featurseactivated se activa.Así que el evento funciona, pero no cuando creo el nuevo sitio. ¿Alguien sabe cómo resolver este problema?

¿Fue útil?

Solución

You are using the rootweb of the site, not the current web, so any changing you are making is always to the rootweb. Instead of using webTemp to get rootweb, just use webTemp as the web.

private const string QuicklaunchHeader = "Saksmappe";

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWeb web = properties.Feature.Parent as SPWeb;
    var rootFolder = web.RootFolder;
    rootFolder.WelcomePage = "Pages/CaseFolder.aspx";
    rootFolder.Update();

    //Remove old custom quick launch entry
    RemoveQuickLaunchItems(QuicklaunchHeader, web);

    //Add custom quick launch entry
    var header = new SPNavigationNode(QuicklaunchHeader, 
                                       web.Navigation.Home.Url,   false);
    web.Navigation.QuickLaunch.AddAsFirst(header);

    //TODO Set correct urls
    header.Children.AddAsLast(new SPNavigationNode("Saksdetaljer", ""));
    header.Children.AddAsLast(new SPNavigationNode("Merknader", ""));
}
Licenciado bajo: CC-BY-SA con atribución
scroll top