How to Perform a Global Find/Replace on the Text/HTML Module in DotNetNuke

Today I will explains how to perform a global find/replace on the text/html module in DNN. If you need to replace content that is stored in the Text/HTML module in your DotNetNuke installation you could manually edit every text/html module, but you can also perform a global find/replace on all the content stored in that module through your database using the script below.

Before starting this process, you should make a complete backup of your website and database.
These steps require you to have Microsoft SQL Server Management Studio installed on your computer. 

declare @FIND as nvarchar(MAX)
declare @REPLACE as nvarchar(MAX)
set @FIND = 'ORIGINAL'
set @REPLACE = 'NEW'
update HtmlText set Content = cast(replace(cast(Content as nvarchar(max)),@FIND, @REPLACE) as ntext)

  • Open Microsoft SQL Server Management Studio and connect to your database.
  • Click on the New Query button.
  • Copy and paste the following script into the New Query window replacing ORIGINAL with your original value and NEW with the new value, please see the note below for information on these values.
  • Click Execute.

Notes
When you are deciding what you want to find and replace, it is best to always be as exact as possible in order to avoid making unintended replacements.  For example, let's say that you recently moved a DotNetNuke website from a virtual directory named /DotNetNuke into the root.    
                                                                                     

You want to update all links so that they remove DotNetNuke.There are a couple different ways that you may be tempted to do this:

Bad
@Find = 'DotNetNuke'
@Replace = ''

The problem with this is that it will find all copies of the word 'DotNetNuke' and replace it with nothing.  With this script, it will replace all instances of 'DotNetNuke', not just ones that are in URLs, so if you have content on your page about DotNetNuke, you'll lose this content.

Acceptable
@Find = '/DotNetNuke/'
@Replace = '/'

This script is better, however, it is not perfect.  Most likely, anywhere that /DotNetNuke/ is listed, it will be part of a URL, however, it won't necessarily be completely accurate.  For example, let's say that you have a URL such as /DotNetNuke/AreasOfExpertise/DotNetNuke/DotNetNukeProjects.aspx when the script above is run, the URL will be shortened to /AreasOfExperties/DotNetNukeProjects.aspx which is most likely not what you would have wanted.

Best
@Find = '"/DotNetNuke/'
@Replace = '"/'

This script is much better because it has the &quot; at the beginning. (This is the encoded version of the double-quote charater).  This is the best is because all URL references are going to follow a pattern similar <a href="/DotNetNuke/Page.aspx">Link</a> or <img src="/DotNetNuke/images/MyImage.gif" /> so we can safely assume that all URLs start with a quote followed by /DotNetNuke/.

TOP Recommended DotNetNuke 7.3.4 Hosting

ASPHostPortal.com is a windows-based hosting service provider. ASPHostPortal.com offers the most reliable and stable DotNetNuke 7.3.4 web hosting infrastructure on the net with great features, fast and secure servers. DotNetNuke 7.3.4 Hosting from ASPHostPortal.com provides a safe, reliable and performance-driven foundation for your  website. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.