Guid featureId = new Guid("0af5989a-3aea-4519-8ab0-85d91abe39ff");
ClientContext clientContext = new ClientContext("http://mysite:786/");
Site clientSite = clientContext.Site;
clientContext.Load(clientSite);
FeatureCollection clientSiteFeatures = clientSite.Features;
clientContext.Load(clientSiteFeatures);
clientContext.ExecuteQuery();
// Activate the feature
clientSite.Features.Add(featureId, true, FeatureDefinitionScope.Site);
//clientSiteFeatures.Remove(featureId, false);
clientContext.ExecuteQuery();
MessageBox.Show("Success");
When I am running this code, I am getting the exception: Feature with id "0af5989a-3aea-4519-8ab0-85d91abe39ff" isn't installed in farm and can't be added to scope.
I got this feature id from the link http://social.technet.microsoft.com/wiki/contents/articles/7695.list-of-sharepoint-2010-features-id-displayname-and-scopes.aspx
Please guide.
Regards, Vikrant Raj Behal
FeatureDefinitionScope.None
这为我激活了网络范围的功能。
According to MSDN the FeatureCollection.Add
method has the following signature
public Feature Add(
Guid featureId,
bool force,
FeatureDefinitionScope featdefScope
)
which is intended for adding the feature to the collection of activated features and returns the added feature
Parameter FeatureDefinitionScope is used for specifying the feature scope for a feature definition. At the same time the documentation says:
It must have the value of
FeatureDefinitionScope.Site
orFeatureDefinitionScope.Farm
It basically means that the method FeatureCollection.Add
does not accept FeatureDefinitionScope.Web
value for featdefScope
and therefore feature activation with Web scope is not supported.
In your case it seems you are trying to activate feature with scope that is not supported (ex. Web) via CSOM
How to verify feature scope
$feature = get-spfeature featureId
if ($feature -eq $null -or $feature -eq "") {
echo "no feature found with id"
} else {
echo ("feature found. Scope is " + $feature.Scope)
}
In order to activate a feature using the Client Object Model, It has to be deployed using a sandbox solution. Features which are deployed via Farm Solutions cannot be activated through the Client Object Model
FeatureDefinitionScope.None
also works for activating Site Collection features.
The way a feature is added (Sandbox, Farm Solution) does not matter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.