sharepoint 各级别Feature 获取及使用

来源:互联网 发布:linux查看jenkins版本 编辑:程序博客网 时间:2024/04/28 13:37

private static void AddFeaturesToTable( ref DataTable dtblFeatureList, string url, SPFeatureScope scope, bool showHidden)

{

    CultureInfo info;

    Dictionary activeFeatures = new Dictionary();

   

    // We need to get the SPSite and SPWeb so that we can get the culture info and any active features if a scope was passed in.

    using (SPSite site = new SPSite(url))

    {

         using (SPWeb web = site.OpenWeb())

         {

              info = new CultureInfo(( int )web.Language, false );

 

              activeFeatures [ SPFeatureScope.Farm ] = SPWebService.ContentService.Features ;

              activeFeatures[SPFeatureScope.WebApplication] = site.WebApplication.Features;

              activeFeatures[SPFeatureScope.Site] = site.Features;

              activeFeatures[SPFeatureScope.Web] = web.Features;

          }

     }

 

     foreach (SPFeatureDefinition definition in SPFarm.Local.FeatureDefinitions)

    {

          try

         {

              Guid featureID = definition.Id;

              // If the scope is marked as invalid then that's our flag that it wasn't provided so we're going to

              // list everything regardless of scope and show those that are active for the Web scope.

             if (definition.Scope != scope && scope != SPFeatureScope.ScopeInvalid)

             continue ;

             if (definition.Hidden && !showHidden)

             continue ;

             if (!definition.SupportsLanguage(info))

             continue ;

 

             bool isActive = false ;

             if (activeFeatures[definition.Scope] != null )

             isActive = (activeFeatures[definition.Scope][featureID] != null );

 

             DataRow row = BuildDataRowFromFeatureDefinition(dtblFeatureList, info, definition, isActive);

             dtblFeatureList.Rows.Add(row);

          }

          catch (SPException)

          {

               continue ;

           }

     }

 

 

摘自 :http://stsadm.blogspot.com/2007/08/enumerate-features.html

原创粉丝点击