internal void DeactivateFeature(Guid _feature, SPFeatureDefinitionScope _scope) { try { SiteCollection.Features.Remove(_feature, false); try { string _tmsg = String.Empty; if (_scope == SPFeatureDefinitionScope.Site) { SiteCollection.FeatureDefinitions.Remove(_feature, true); _tmsg = String.Format("Removed the definition of the feature Id={0} at the site Url={1}.", _feature, SiteCollection.Url); } else { FarmHelpers.Farm.FeatureDefinitions.Remove(_feature, true); _tmsg = String.Format("Removed the definition of the feature Id={0} at the Farm DisplayName={1}.", _feature, FarmHelpers.Farm.DisplayName); } Tracing.TraceEvent.TraceVerbose(90, "SiteCollectionHelper.DeactivateFeature", _tmsg); } catch (Exception _ex) { string _msg = String.Format("I cannot remove definition for the feature Id = {0} at the site Url = {1} because {2}.", _feature, SiteCollection.Url, _ex.Message); Tracing.TraceEvent.TraceVerbose(95, "SiteCollectionHelper", _msg); } } catch (Exception ex) { string _msg = String.Format(Resources.FeatureDeactivationFailed, _feature, SiteCollection.Url, ex.Message); throw new ApplicationException(_msg); ; } }
private void iInstallFeature(Guid gFeatureId, SPFeatureDefinition def, SPFeatureDefinitionScope scope, int ParentMessageId) { switch (def.Scope) { case SPFeatureScope.Site: if (!bVerifyOnly) { oWeb.Site.Features.Add(gFeatureId, true, scope); } addMessage(ErrorLevels.NoError, def.DisplayName, string.Empty, ParentMessageId); break; case SPFeatureScope.Web: if (!bVerifyOnly) { oWeb.Features.Add(gFeatureId, true, scope); } addMessage(ErrorLevels.NoError, def.DisplayName, string.Empty, ParentMessageId); break; default: addMessage(ErrorLevels.Warning, def.DisplayName, "Feature Not scoped for Site or Web", ParentMessageId); break; } }
public static SPFeature ActivateOneFeature(SPFeatureCollection features, Guid featureId, ILog log) { bool force = true; #if SP2013_UNUSED // Unneeded - 14/15 hive deployment is governed at solution deployment time // Full-blown solution, not sandboxed SPFeatureDefinitionScope featureScope = SPFeatureDefinitionScope.Farm; // Note: 2013-03-20 // This does not appear to work, at least with an SP2010 wsp // it appears to always get activated at level 14 // This article describes an undocumented workaround // http://www.boostsolutions.com/blog/how-to-install-a-farm-solution-in-2010-and-2013-mode-for-sharepoint-2013/ if (InstallConfiguration.CompatibilityLevel == "14" || InstallConfiguration.CompatibilityLevel.ToUpper() == "OLD" || InstallConfiguration.CompatibilityLevel.ToUpper() == "OLDVERSION" || InstallConfiguration.CompatibilityLevel.ToUpper() == "OLDVERSIONS" ) { log.Info("Activating feature at level 14: " + featureId.ToString()); return(features.Add(featureId, 14, force, featureScope)); } else if (InstallConfiguration.CompatibilityLevel == "15" || InstallConfiguration.CompatibilityLevel.ToUpper() == "NEW" || InstallConfiguration.CompatibilityLevel.ToUpper() == "NEWVERSION" || InstallConfiguration.CompatibilityLevel.ToUpper() == "NEWVERSIONS" ) { log.Info("Activating feature at level 15: " + featureId.ToString()); return(features.Add(featureId, 15, force, featureScope)); } else if (InstallConfiguration.CompatibilityLevel == "14,15" || InstallConfiguration.CompatibilityLevel.ToUpper() == "ALL" || InstallConfiguration.CompatibilityLevel.ToUpper() == "ALLVERSIONS" ) { log.Info("Activating feature at level 14 then 15: " + featureId.ToString()); features.Add(featureId, 14, force, featureScope); return(features.Add(featureId, 15, force, featureScope)); } else { return(features.Add(featureId, force)); } #else return(features.Add(featureId, force)); #endif }
public static FeatureDefinitionScope ToFeatureDefinitionScope(this SPFeatureDefinitionScope scope) { switch (scope) { case SPFeatureDefinitionScope.None: return(FeatureDefinitionScope.None); case SPFeatureDefinitionScope.Farm: return(FeatureDefinitionScope.Farm); case SPFeatureDefinitionScope.Site: return(FeatureDefinitionScope.Site); case SPFeatureDefinitionScope.Web: return(FeatureDefinitionScope.Web); default: throw new ArgumentException( string.Format("Unexpected, undefined SPFeatureDefinitionScope '{0}' found", scope.ToString())); } }
private static void ActivateFeatures(ISharePointCommandContext context, FeatureActivationInfo activationInfo) { SPFeatureDefinitionScope scope = activationInfo.IsSandboxedSolution ? SPFeatureDefinitionScope.Site : SPFeatureDefinitionScope.Farm; foreach (DeploymentFeatureInfo featureInfo in activationInfo.Features) { context.Logger.WriteLine(String.Format("Activating Feature {0}...", featureInfo.Name), LogCategory.Status); if (featureInfo.Scope == DeploymentFeatureScope.Web) { context.Web.Features.Add(featureInfo.FeatureID, false, scope); } else if (featureInfo.Scope == DeploymentFeatureScope.Site) { context.Site.Features.Add(featureInfo.FeatureID, false, scope); } else if (featureInfo.Scope == DeploymentFeatureScope.WebApplication) { context.Site.WebApplication.Features.Add(featureInfo.FeatureID, false, scope); } } }
internal SPFeature ActivateFeature(Guid _feature, SPFeatureDefinitionScope _scope) { try { int _try = 0; do { try { SPFeatureDefinition _def; string _tmsg = String.Empty; if (_scope == SPFeatureDefinitionScope.Site) { _def = SiteCollection.FeatureDefinitions.First(_fd => { return(_feature == _fd.Id); }); _tmsg = String.Format("Found the definition of the feature Id={0} at the site Url={1} DisplayName={2}.", _feature, SiteCollection.Url, _def.DisplayName); } else { _def = FarmHelpers.Farm.FeatureDefinitions.First(_fd => { return(_feature == _fd.Id); }); _tmsg = String.Format("Found the definition of the feature Id={0} at the Farm DisplayName={1}.", _feature, FarmHelpers.Farm.DisplayName); } Tracing.TraceEvent.TraceVerbose(90, "SiteCollectionHelper", _tmsg); break; } catch (Exception) { } string _msg = String.Format("I cannot find definition for the feature Id = {0} at the site Url = {1} attempt {2} form 5.", _feature, SiteCollection.Url, _try++); Tracing.TraceEvent.TraceVerbose(95, "SiteCollectionHelper", _msg); Thread.Sleep(1000); } while (_try < 5); return(SiteCollection.Features.Add(_feature, false, _scope)); } catch (Exception ex) { string _msg = String.Format(Resources.FeatureActivationFailed, _feature, SiteCollection.Url, _scope, ex.Message); throw new ApplicationException("SiteCollectionHelper.ActivateFeature: " + _msg); ; } }
public static SPFeature ActivateFeatureIfNecessary(SPWeb web, Guid featureGuid, bool force, SPFeatureDefinitionScope sPFeatureDefinitionScope) { web.RequireNotNull("web"); featureGuid.Require(Guid.Empty != featureGuid, "featureGuid"); SPFeature feature = web.Features[featureGuid]; if (null == feature || force) { feature = web.Features.Add(featureGuid, force, sPFeatureDefinitionScope); } return feature; }
public SPFeature ActivateFeatureIfNecessary(SPSite site, Guid featureGuid, bool force, SPFeatureDefinitionScope sPFeatureDefinitionScope) { return SharePointUtilities.ActivateFeatureIfNecessary(site, featureGuid, force, sPFeatureDefinitionScope); }