2009-04-22 5 views
0

私たちは、すぐに利用可能なコンテンツエディタWebパーツを使用してコンテンツを開発したSharePoint Webサイトを持っています。これは、IE以外のブラウザを使用する場合には少しゴミです。1つのWebパーツをSharepointの別のWebパーツでプログラム的に置き換えることはできますか?

は、私たちは、しかし、我々は、Webパーツの上にスワップするために自分自身のコピーと貼り付け、およびクリックして選択を大量に保存したい、無料Telerikコンテンツエディタに更新する心を持っています。

正式なアップグレードパスはないようですが、元のwebpartの内容を取得して、telerik webopartを新規作成してコンテンツを入れるためには、コード(tm)を使用することが可能でなければならないようです。新しいWebパーツ...古いオリジナルWebパーツを削除します。

誰もこの種のことをしましたか?どのようにコードをレイアウトし、実際にスワップを行うコードを実行するのが最善でしょうか(可能な場合)。新しい「Do Swap」ボタンが付いたWebパーツはありますか?それとももっと洗練された何か?

私も(サブサイトで、ページ)すべてのページとサブサイトを歩く必要があり、すべてのWebパーツになります。これを行うベストプラクティスの方法はありますか?

ありがとうございました。

答えて

2

私はこのためのコンソールアプリケーションを作成します。

を開き、ルートWebとそのサブウェブを反復。 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のコントロールがそのコンテンツの最初の編集時にちょっと驚くようになるかもしれませんが、コンテンツを再フォーマットして復旧するには問題ありません。

関連する問題