SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Install and activate a feature to all current sites, and future sites.

Last post 12-12-2008, 12:15 PM by dhunter. 8 replies.
Sort Posts: Previous Next
  •  12-11-2008, 10:44 AM 16172

    Install and activate a feature to all current sites, and future sites.

    Hi,

     I've been working on 2 projects which needs to be tied together using another feature.

    Project 1.
    A custom field type that is a Regular Expression Field. When configuring the RegEx field, you choose which Regular Expression you wish to enforce using a combo box. This combo box gets it data from an XML file. This is installed as a solution globally with no feature.

    Project 2.
    A global config document library. Installed directly to the SharePoint Central Administration Site. When installed it creates a document template, then document library based on new content type also created on install. Once installed the XML file required for project 1 is added. There is also a class created that is used in project 1 that can call the document library. This is installed as a solution for the Central Adminstration Site only.

    How the class for accessing the XML file works is reading a config value in the web.config of the web site, which tells the site where the Central Administration site is, and what the Global Config Document Library is called. (This is all similar to Chris 'o Briens Local config store http://www.sharepointnutsandbolts.com/2008/05/config-store-faqs.html).

    I've created a feature called ActivationForGlobalConfig, which upon activation will insert the correct appSetting values required in the web config to access the global configuration store. Due to the fact I'm using the Global config store with a custom field type, that will be visible in every site, I need to edit the web.config for every current web application, and every future web application created in the farm.

    How to I create a feature that can be deployed to every current web application, and future application that will activate on default? I've tried using the features ActivateOnDefault="True" but it doesn't seem to do anything.

    Regards

    Paul.

  •  12-11-2008, 2:42 PM 16185 in reply to 16172

    Re: Install and activate a feature to all current sites, and future sites.

    Hi Paul

    If you want the above feature to be activted on all new sites, you may want to look at a stapling feature, this will basically ensure that your features event recivers will be tied to a particular site or list from then on, as for current sites, you may have to look at creating a custom script that just itterates through the sites and activates the feature against it.

    I hope this helps, theres plenty to read up on Feature Stapling, so this should get you up and running :)

    Andrew Carter
    .Net & SharePoint Consultant

    See my blog at: http://blog.apc-solutions.co.uk
  •  12-11-2008, 2:54 PM 16186 in reply to 16172

    Re: Install and activate a feature to all current sites, and future sites.

    Hi Andrew,

     Thankyou. Since this morning I have looked into Feature Stapling. Unfortunately I've haven't been able to get it to work.

    I've created another feature which is at farm level.

    Feature.xml

    <Feature Id="7058D64D-A918-43bb-98E5-03F1831C3328"
    Title="Stappling Feature to Global Template"
    Description="Stappling Activation to use Global Configuration Stores feature to Global Template"
    Version="1.0.0.0"
    Scope="Farm"
    xmlns="http://schemas.microsoft.com/sharepoint/"
    Hidden="False"
    ActivateOnDefault="True"
    SolutionId="DEC46F01-D12F-46b4-AC3E-AC5EDA451CEB">
    <
    ElementManifests>
    <ElementManifest Location ="elements.xml"/>
    </
    ElementManifests>
    </Feature>

    Elements.xml

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <
    FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="GLOBAL"/>
    </
    Elements>

    The feature that I'm stapling
    <?xml version="1.0" encoding="utf-8" ?>
    <
    Feature xmlns="http://schemas.microsoft.com/sharepoint/"
    Id="{4C11105D-DAE9-4cc3-8346-E5474F2028B4}"
    Title="Activation to use Global Configuration Stores"
    Description="Allows the site to use the Global Configuartion Stores, stored at the SharePoint Central
    Administration level.
    "
    Version="12.0.0.0"
    Scope="Site"
    Hidden="FALSE"
    DefaultResourceFile="core"
    ReceiverAssembly="CompanyIWorkFor.SharePoint.Utilities.ActivationForGlobalConfig, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0bee8813e4da67a1"
    ReceiverClass="CompanyIWorkFor.SharePoint.Utilities.ActivationForGlobalConfig.ActivationForGlobalConfigFeatureReceiver" >
    <
    ElementManifests>
    </
    ElementManifests>
    </
    Feature>

    After installing this feature into the farm, although the feature is activated at Farm Level, when I create a new blank site, the feature I've stapled hasn't been activated. I've only tested blank site.

    It's a I dislike SharePoint day for me!

     

  •  12-12-2008, 8:51 AM 16197 in reply to 16186

    Re: Install and activate a feature to all current sites, and future sites.

    I think the issue you may be having is you are using the Global templatename, i can't seem to find confitmation, but from past experince, any stapled features will not get automatically activated if you use the Global Template, instead you have to specify the templates directly like below:

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="SPSMSITE#0" />

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="SPSTOC#0" />

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="SPSTOPIC#0" />

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="SPSNEWS#0" />

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="SPSNHOME#0" />


    Etc....


    Hopefully that will sort it for you, i have many i hate SP days too, but makes for part of the fun \o/

    Andrew Carter
    .Net & SharePoint Consultant

    See my blog at: http://blog.apc-solutions.co.uk
  •  12-12-2008, 9:55 AM 16202 in reply to 16197

    Re: Install and activate a feature to all current sites, and future sites.

    Annoyingly it seems that you are right. I've just tested my feature stapling based only on the Blank site, and it automatically activated the feature.

    It seems pointless to use the Global template at all then.

    Which now means that I have to ensure that it's stapled to every template, and any future templates we create, that this piece of code is updated.

     

  •  12-12-2008, 10:23 AM 16205 in reply to 16202

    Re: Install and activate a feature to all current sites, and future sites.

    Hi,

    The global template does work, but the only site template is doesn't work for is the blank template.  To cover all future site templates and existing ones you will need the following two site template associations

    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="GLOBAL" />
    <FeatureSiteTemplateAssociation Id="4C11105D-DAE9-4CC3-8346-E5474F2028B4" TemplateName="STS#1" />

    The reason why it doesn't work for the blank site template because it explicity sets AllowGlobalFeatureAssociations to false.

    Please see this great article from Ted Pattison http://blog.tedpattison.net/Lists/Posts/Post.aspx?ID=2

    Hope this helps

    Dave


    My SharePoint Blog http://www.davehunter.co.uk
  •  12-12-2008, 10:30 AM 16206 in reply to 16205

    Re: Install and activate a feature to all current sites, and future sites.

    Thanks for posting that link Dave ,that totally clarifys what was happening to me :), good to know i was not going mad and just having to frig a solution, ofcourse it all makes perfect sense now. Ah the internet!. (thanks to Ted too for the blog post!)

    Andrew Carter
    .Net & SharePoint Consultant

    See my blog at: http://blog.apc-solutions.co.uk
  •  12-12-2008, 10:35 AM 16208 in reply to 16205

    Re: Install and activate a feature to all current sites, and future sites.

    Hi Dave,

    Brillant. Thank you.

    I'll add that to my list of another piece of SharePoint Functionality Microsoft didn't complete.

  •  12-12-2008, 12:15 PM 16212 in reply to 16208

    Re: Install and activate a feature to all current sites, and future sites.

    I don't think its functionality MS didn't complete, it would of been easier to let the Blank Site using the global features but instead they choose to explicity exclude from the global feature set.  This sounds more like a design consideration.

    The blank site doesn't have any lists provisioned but still using the collaboration team features (you can see this in the onet.xml), so I'm lost what is the design consideration actually is .... usually when you can't find an answer its to do with legacy support.

    SharePoint has evolved throughout its lifecycle (starting from the acquisition of VTI to the present day), but MS still has to support legacy applications that have been migrated into the net platform without requiring major code re-writing.  MS re-wrote large sections of the API for Commerce Server so it utilised .NET but still had to keep old calls for previous versions (that used interop).

    We just have to work with these quirks :)

    Dave


    My SharePoint Blog http://www.davehunter.co.uk
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems