2010-12-08 52 views
2

我遇到了一個需要解決的問題。我想遍歷根站點及其所有子網站,並要設置一些屬性如何從根網站及其所有子網站循環訪問

+0

我提供給您的解決方案相同的,但一個校正可以爲圖片庫中不採用同樣的圖片庫不支持內容審批,所以如果您必須將解決方案應用於其他類型的列表,您可以這樣做 – 2010-12-08 11:24:14

+0

感謝您的代碼,但是如何在每個網頁中設置圖像列表的屬性? – 2010-12-08 15:33:26

回答

2
using (SPSite oSPsite = SpSecurityHelper.GetElevatedSite(GetSiteCollection(properties))) 
     { 
      SPWebCollection siteWebs = oSPsite.AllWebs; 
      foreach (SPWeb web in siteWebs) 
      { 
       try 
       { 
        SPList list = null; 
        try 
        { 
         list = web.Lists["Images"]; 
        } 
        catch { } 

        if (list != null) 
        { 

         list.EnableModeration = isEnabled == false ? false: true; 
         list.Update(); 
        } 
       } 
       finally 
       { 
        if (web != null) 
         web.Dispose(); 
       } 
      } 
     } 
5
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.SharePoint; 

namespace ConsoleApplication2 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      using (SPSite oSPsite = new SPSite("http://sharepointdev:2021")) 
      { 
       using (SPWeb oSPWeb = oSPsite.OpenWeb()) 
       { 
        foreach (SPList list in oSPWeb.Lists) 
        { 
         if (list.ContentTypes.Count > 0) 
         { 

          foreach (SPContentType contentType in list.ContentTypes) 
          { 
           if (contentType.Name == "Document") 
           { 
            list.EnableModeration = true; 
            list.Update(); 
           } 
          } 
         } 
        } 

        if(oSPWeb.Webs.Count > 0) 
        recursivewebcheck(oSPWeb); 
       } 
      } 
     } 



     static void recursivewebcheck(SPWeb oSPWeb) 
     { 

      foreach (SPWeb web in oSPWeb.Webs) 
      { 
       foreach (SPList list in oSPWeb.Lists) 
       { 
        if (list.ContentTypes.Count > 0) 
        { 

         foreach (SPContentType contentType in list.ContentTypes) 
         { 
          if (contentType.Name == "Document") 
          { 
           list.EnableModeration = true; 
           list.Update(); 
          } 
         } 
        } 
       } 

       if (web.Webs.Count > 0) 
       { 
        recursivewebcheck(web); 
       } 
       web.Dispose(); 
      } 

     } 
    } 
}