2009-04-22 67 views
0

我們有一個sharepoint網站,使用開箱即用的內容編輯器webpart,已經開發了相當豐富的內容。當涉及到使用除IE之外的其他瀏覽器時,這有點垃圾。我可以使用Sharepoint中的另一個webpart替換另一個webpart嗎?

我們心裏有更新的免費Telerik的內容編輯,但是我們想向大家節省大量的複製和粘貼,並單擊並選擇交換網絡部分結束。

似乎沒有正式的升級途徑,但在我看來,必須有可能使用代碼(tm)的力量來抓取原始webpart的內容,新增telerik webopart並將內容放入新的webpart ...然後刪除舊的原始web部分。

有沒有人做過這樣的事情?如何最好地佈置代碼並實際運行將執行交換的代碼(如果可能的話)。一個新的webpart上有一個「Do Swap」按鈕?或更復雜的東西?

我還需要通過每個頁面和子網站(和頁面的子網站)行走,並期待在每一個網絡的一部分。有這樣做的最佳做法嗎?

謝謝,對不起,是一個有點rambley!

回答

2

我會爲此編寫一個控制檯應用程序。

打開根網站並反覆通過其子站點。 通過打開WebPartManager來完成每個頁面所需的工作。

這裏有一些僞代碼讓你開始。

string SourceUrl = "http://ThisWeb"; 

using (SPSite sourceSite = new SPSite(SourceURL)) 
{ 
    using (SPWeb sourceWeb = sourceSite.OpenWeb(SourceURL)) 
    { 
     IterateSubWebsProd(sourceWeb): 
    } 
} 

private void IterateSubWebsProd(SPWeb sourceWeb) 
{ 
    // This is the migration function 
    DoThingyWithThisWeb(sourceWeb); 

    foreach (SPWeb subWeb in sourceWeb.Webs) 
    { 
     IterateSubWebsProd(subWeb); 
     subWeb.Dispose(); 
    } 
} 

private void DoThingyWithThisWeb(SPWeb sourceWeb) 
{ 
    PublishingPage currentPage = null; 

    string currentPageName = "<something>"; 
    // Find the pages that you want to modify, with a CAML query for example 
    SPQuery query = new SPQuery(); 
    query.Query = string.Format("" + 
    "<Where>" + 
     "<Eq>" + 
     "<FieldRef Name='FileLeafRef' />" + 
     "<Value Type='File'>{0}</Value>" + 
     "</Eq>" + 
    "</Where>" + 
    "", currentPageName); 


    // This codesnippet is from a Publishing web example 
    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(sourceWeb); 
    PublishingPageCollection pageColl = publishingWeb.GetPublishingPages(query); 
    if (pageColl.Count > 0) 
    { 
     currentPage = pageColl[0]; 
    } 

    using (SPLimitedWebPartManager wpMan = currentPage.ListItem.File.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)) 
    { 
     foreach (WebPart wp in wpMan.WebParts) 
     { 
      if (wp.GetType().Equals(typeof(Microsoft.SharePoint.WebPartPages.ContentEditorWebPart))) 
      { 
       Microsoft.SharePoint.WebPartPages.ContentEditorWebPart thisWebPart = wp as Microsoft.SharePoint.WebPartPages.ContentEditorWebPart; 

       // This is just dummy code, here you will do your content migration 
       XmlDocument xmlDoc = new XmlDocument(); 
       XmlElement xmlElement = xmlDoc.CreateElement("RootElement"); 
       xmlElement.InnerText = sourceItem[SourceField].ToString(); 
       thisWebPart.Content = xmlElement; 

       wpMan.SaveChanges(thisWebPart); 
      } 
     } 
    } 
} 
1

我不是這個100%肯定,但如果你的內容保存到一個列表作爲單獨的領域,你能不能點Telerik的地方,在這些內容被保存控制?這可能會導致Telerik控件在該內容的第一次編輯時出現一些偏差,但是應該可以重新格式化內容並進行恢復。