More in this section

Forums / General Discussions / Content Search / Replace

Content Search / Replace

4 posts, 0 answered
  1. Seattle Web Group
    Seattle Web Group avatar
    29 posts
    03 May 2011
    27 Aug 2011
    Link to this post
    Is there a tool or snippet of code available to do a search / replace in all of the generic HTML content entered onto a Sitefinity site?  We've got some content to update and it will be far faster in this case if we can do a general search / replace on content entered into the site rather than going through the pages and individually editing them.
  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    03 Nov 2014
    31 Aug 2011
    Link to this post
    Hi Seattle Web Group,

    You can use a code similar to this:

    var manager = ContentManager.GetManager();
    var items = manager.GetContent().Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
    foreach (var item in items)
        var content = item.Content.Value;
        item.SetValue("Content", newValue);

    Best wishes,
    Lubomir Velkov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Basem
    Basem avatar
    131 posts
    22 Dec 2010
    24 Oct 2011
    Link to this post
    The provided code only works for shared content blocks. I am trying to replace the HTML content in all my pages, but not everything is a shared content block. How can I adjust this so it processes on all generic content and not just shared ones?

    var contentItem = manager.GetContent().Where(c =>c.Content.Contains(search) && c.Status == ContentLifecycleStatus.Live);
  4. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    30 Oct 2017
    27 Oct 2011
    Link to this post
    Hi Basem,

    We have replied to you in the support thread you had open, for your convenience please find our reply below as well:
    To get or modify the Content block Html property, you'll need to traverse the controls on your page, get the ones whose ObjectType is ContentBlock, and then obtaint he Html property. An important thing to note is that once you've done modifying the properties of the loaded control, you'll need a call to PageManager.ReadProperties() which will copy the properties of the loaded content block which you've modified to the actual control representation on the page. Please find below a sample code on how you can achieve this:
    var pageManager = PageManager.GetManager();
                var pageDataList = pageManager.GetPageDataList()
                                              .Where(pD => pD.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && pD.HtmlTitle == "Scheduler")
                foreach (PageData pageData in pageDataList)
                    var contentBlocks = editPage.Controls.Where(c => c.ObjectType.StartsWith(typeof(ContentBlock).FullName));
                    foreach (var contentBlockControl in contentBlocks)
                        ContentBlock contentBlock = pageManager.LoadControl(contentBlockControl) as ContentBlock;
                        contentBlock.Html = "EDITED from CODE";
                        pageManager.ReadProperties(contentBlock, contentBlockControl);
                    pageManager.PublishPageDraft(editPage.Id, true);

    If you need some additional information on this functionality, please let us know, we'll be glad to help.

    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered