Content Search / Replace

Posted by Community Admin on 03-Aug-2018 00:08

Content Search / Replace

All Replies

Posted by Community Admin on 27-Aug-2011 00:00

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.

Posted by Community Admin on 31-Aug-2011 00:00

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)
    Lstring
    var content = item.Content.Value;
    item.SetValue("Content", newValue);
 
manager.SaveChanges();


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 >>

Posted by Community Admin on 24-Oct-2011 00:00

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

Posted by Community Admin on 27-Oct-2011 00:00

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")
                                          .ToList();
  
            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.SaveChanges();
                
                pageManager.PublishPageDraft(editPage.Id, true);
            
            pageManager.SaveChanges();
"

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

Regards,
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

This thread is closed