2011-10-21 8 views
0

私はSP2010でプログラムでサイトコレクションをプロビジョニングしています。プロセスは正常に動作していますが、リッチテキストに含まれるホームページのテキストをカスタマイズする必要があります(Webパーツではありません)。 HTMLコードを取得してコードから変更する方法はありますか?たとえば、ホームページに埋め込まれている場合、私はタイトルとテキストの段落を持っています。私はプロビジョニング要求から提供された入力値の1つに基づいてタイトルをカスタマイズしたいと思います。これは可能ですか?任意の提案をいただければ幸いです!ホームページでリッチコンテンツをプログラムで変更する

答えて

0

次のように、コンテンツ領域にアクセスすることができます。

PublishingWeb pw = null; 
//"web" is your SPWeb, didn't include using statement for your SPSite/SPWeb in this sample 
if (PublishingWeb.IsPublishingWeb(web)) 
{ 
    pw = PublishingWeb.GetPublishingWeb(web); 
} 
//todo: add some handling here for if web is not a publishingWeb 
//assuming your home page is the default, if not - get the correct page here 
SPFile defaultpage = pw.DefaultPage; 
if (!(defaultpage.CheckOutType == SPFile.SPCheckOutType.None)) 
{ 
    //programatically creating this stuff, so cancel any unexpected checkouts 
    defaultpage.UndoCheckOut(); 
} 
defaultpage.CheckOut(); 
//Field you want to add HTML in (Alternatively, retreive existing data and modify the HTML) 
defaultpage.ListItemAllFields["PublishingPageContent"] = "string of HTML"; 
defaultpage.ListItemAllFields.Update(); 
defaultpage.CheckIn("My Comment"); 
+1

は、あなたの迅速な対応をありがとうございました。追加の掘り下げの後、私は出版を実装していないと言われたので、これは私にとって実行可能な解決策ではありません。変更を新しいページレイアウトに組み込むように思えます。あなたの明快で簡潔な答えに感謝し、最終的に誰かを助けることを願っています。 – user1007118

関連する問題