【发布时间】:2011-10-21 22:06:56
【问题描述】:
我在 SP2010 中以编程方式配置网站集。该过程运行良好,但我需要能够自定义主页上包含在富文本(而不是 Web 部件)中的一些文本。有没有办法获取该 HTML 代码并从代码中修改它?例如,嵌入在主页中,我有一个标题和一段文字。我想根据供应请求提供的输入值之一自定义标题。是否有可能做到这一点?任何建议将不胜感激!
【问题讨论】:
标签: c# sharepoint-2010
我在 SP2010 中以编程方式配置网站集。该过程运行良好,但我需要能够自定义主页上包含在富文本(而不是 Web 部件)中的一些文本。有没有办法获取该 HTML 代码并从代码中修改它?例如,嵌入在主页中,我有一个标题和一段文字。我想根据供应请求提供的输入值之一自定义标题。是否有可能做到这一点?任何建议将不胜感激!
【问题讨论】:
标签: c# sharepoint-2010
您可以通过以下方式访问内容区:
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");
【讨论】: