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

DNN > How To

How to Perform a Global Find/Replace on the Text/HTML Module in DotNetNuke
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. To install MSSQL, please view the following article: How to Connect to MSSQL.
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)
  1. Open Microsoft SQL Server Management Studio and connect to your database.
  2. Click on the New Query button.
  3. 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.
  4. Click Execute.
  5. Recycle your site's application pool following the instructions in our How to Recycle the Application Pool of a Website article.

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 " at the beginning. (This is the encoded version of the double-quote charater).

Feedback

Add Feedback
what is the limit number of characters for this procedure and do I have to substitute these signs: >, <, " with > < and so on. Thanks
Igor Tverskoy (January 18, 2014 at 3:59 PM)

Add Feedback