Join our DNN Community    (Newsletter, Tips, Tricks and Forums for DNN Skins & Modules)

 


 
Microsoft Gold Certified Partner - DNN Benefactor

DotNetNuke Powered! 


Friday, November 21, 2008 Register · Login · Contact · Search:  
Company Solutions Portfolio Contact
Forums
Tips and Tricks
Discussion of the popular 'Tips and Tricks' from the Newsletter. Questions or comments regarding the provided tips, or other general tricks of the trade.
Subject: Find and Replace Procedure for Html Module
You are not authorized to post a reply.
Page 2 of 2 << < 12
 
Author Messages
stefanp
Flyweight
Posts:2

09/06/2007 8:33 AM Alert 
Thanks, that worked great.

I now notice that the are other modules like Announcements (News) and Links that have broken image links.

I tried modifying the code for the Replace_DestopHTML proc to do a search and replace in the Announcements table but it looks like this table can return multiple ModuleIds for a single announcement so the procedure doesn't work and I'm not savvy enough in SQL Server stored proc development to make the code change.

Anyway, I used the follwing code which searches all DNN tables to find potentiallly problematic image links:

CREATE PROC SearchAllTables
(
@SearchStr nvarchar(100)
)
AS
BEGIN

-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Tested on: SQL Server 7.0 and SQL Server 2000
-- Date modified: 28th July 2002 22:50 GMT
-- Searches only the following data types: 'char', 'varchar', 'nchar', 'nvarchar' (not 'ntext')

-- usage EXEC SearchAllTables 'Computer'
-- GO



CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)

WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)

IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Results
EXEC
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END

SELECT ColumnName, ColumnValue FROM #Results
END
rami
Flyweight
Posts:1

07/24/2008 1:52 AM Alert 
hi ,

mmm ok if i have more than one url in the same row ?
this prosuder checking if it's have one or more than one url to replace it ?

thank you
really well do <img src='http://dnn.bi4ce.com/desktopmodules/ntforums/images/emoticons/wow.gif' height='20' width='20' border='0' title='Wow' align='absmiddle'>
robert_chumley
Please Wait...
Posts:595

08/06/2008 11:12 AM Alert 
You may need to experiment with this solution to determine if it is getting everything and solving all the broken link problems. It appears this script will work in that scenario to replace multiple occurrences. We strongly urge you to do a full set of tests on the process before committing the final batch. As with all Find and Replace algorithms, it could lend itself to unexpected results fairly easily.
Thanks,

Robert Chumley
r2integrated (formally bi4ce)
nonstopmark
Flyweight
Posts:1

09/23/2008 11:46 AM Alert 
I have just applied the create procedure above and applied it to a locally hosted website (previously hosted) and all images are displayed. Excellent.

Am I right in thinking that if I re-deploy the website to a hosted account with a domain name, I re-apply the procedure below...

Replace_DesktopHtml '/Portals/0/','';

But in reverse, e.g.

Replace_DesktopHtml '','/Portals/0/';

Thanks in advance for all you help here...

Cheers

MARK.
www.markwhitfield.net
bgates
Heavyweight
Posts:197

10/05/2008 12:14 PM Alert 
BAD IDEA! I fear that would actually replace all content with just '/Portals/0/'. If you're replacing images, you may want a more directed replacement like:

Replace_DesktopHtml 'src="/images"', 'src="/Portals/0/images"'

Bob Gates
Business Intelligence Force, Inc. (bi4ce)
You are not authorized to post a reply.
Page 2 of 2 << < 12
Forums > Dotnetnuke > Tips and Tricks > Find and Replace Procedure for Html Module



ActiveForums 3.6
Latest Post
 
At R2integrated (formerly Bi4ce), we take support seriously.  That's why we support our customers and DNN community with daily monitoring from our experienced engineering team.  We ask that the first step taken is to read the relevant documentation and support forums prior to submitting any questions that may already be available or have been answered.  We ask that you review the documentation that we provide for our products before posting a question.

The Forums are for our customers to chat, exchange ideas and strategies, and submit feedback.  Please be sure to perform keyword searches for previous related forum responses.

To be helpful when submitting a new item, please include the following: 
  1. DNN Version
  2. Module Version
  3. Admin Log Viewer Information
  4. Environment detail: Operating system, .NET framework version, database and version, IIS version, Browser version (if appropriate)
We always try to respond quickly and monitor the forums daily during business hours (EST).  Occasionally, requests for a specific project requirement may not apply for the free support offered. For project specific support please submit via our Information Request form.

Thank you for using our Forums.

Click here to register for the Forums
 
© 2008 by R2integrated (formerly Bi4ce) | DNN® is a registered trademark of DotNetNuke Corporation