[英]Modify the content of the home page programmatically in SharePoint 2010
[英]Modifying rich content on home page programmatically
我正在SP2010中以編程方式配置網站集。 該過程運行正常,但我需要能夠自定義包含在富文本格式(而不是Web部件)中的主頁上的某些文本。 有沒有辦法獲取該HTML代碼並從代碼中對其進行修改? 例如,嵌入首頁中,我有一個標題和一段文本。 我想根據配置請求提供的輸入值之一來定制標題。 是否有可能做到這一點? 任何建議,將不勝感激!
您可以按如下方式訪問內容區域:
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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.