Activation de feature sandbox par code 

Tags: 2010, Feature, Sandbox, SharePoint

Décidément, le développement de Sandbox solutions nécessite une connaissance bien spécifique.

Supposons que l’on possède une solution Sandbox qui soit activée au niveau d’une collection de site. Cette Sandbox possède une feature de scope “Site”. Comment l’activer par code ?

En standard, on ferait ça comme ça :

site.Features.Add(GUID_FEATURE);

A l’exécution, on se prend une belle erreur :

Feature with Id … is not installed in this farm, and cannot be added to this scope.

Pour les feature sandbox, il faut à la place, utiliser la méthode suivante :

site.Features.Add(GUID_FEATURE, false, SPFeatureDefinitionScope.Site);

 

En effet, sur MSDN, il est bien précisé pour la méthode suivante :

public SPFeature Add(
    Guid featureId
)

“This overload of the Add method can be used only with Feature definitions that have been deployed at the farm level”

 

Alors que la surcharge suivante permet de préciser le scope de la feature definition

public SPFeature Add(
    Guid featureId,
    bool force,
    SPFeatureDefinitionScope featdefScope
)

“To activate an instance of a Feature that is made available through sandboxed solutions, pass SPFeatureDefinitionScope.Site as the argument”

CQFD

 
Posted by Sylvain on 17-Jan-12
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments

Nom *:
URL:
Email:
Commentaires:
CAPTCHA Image Validation