【问题标题】:Modifying rich content on home page programmatically以编程方式修改主页上的丰富内容
【发布时间】:2011-10-21 22:06:56
【问题描述】:

我在 SP2010 中以编程方式配置网站集。该过程运行良好,但我需要能够自定义主页上包含在富文本(而不是 Web 部件)中的一些文本。有没有办法获取该 HTML 代码并从代码中修改它?例如,嵌入在主页中,我有一个标题和一段文字。我想根据供应请求提供的输入值之一自定义标题。是否有可能做到这一点?任何建议将不胜感激!

【问题讨论】:

    标签: c# sharepoint-2010


    【解决方案1】:

    您可以通过以下方式访问内容区:

    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");
    

    【讨论】:

    • 感谢您的快速回复。经过一些额外的挖掘,我被告知我们没有实施发布,所以这对我来说不是一个可行的解决方案。听起来我们会将我们的更改合并到新的页面布局中。感谢您清晰、简洁的回答,希望它最终会对其他人有所帮助。
    猜你喜欢
    • 2012-09-09
    • 2015-07-18
    • 2010-10-20
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2014-08-16
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多