Actualités développement .NET

Actualités DotNetNuke Pro et Communitaire et autres technologies mises en oeuvre par DevPCI.
04
In the previous article we have seen how replace spaces with dash - from page name to url :

#DotNetNuke 6 + 7 Replace page name space with dash in url insted of remove spaces.

Actually, when you have a page named "Char à accént" it result in an url like /Charàaccént.aspx

We will create a new scalar function to replace spaces with dash - and accented char with unaccented ones, and then remove other special characters. we will name it RRStingCharacters , RR for Replace and Remove (this is the same asx the Stored procedure create in previous article.)

/****** Object:  UserDefinedFunction [dbo].[RRStringCharacters]   

SET ANSI_NULLS ON

GO

 

SET QUOTED_IDENTIFIER ON

GO

 

CREATE FUNCTION [dbo].[RRStringCharacters]

(

             @VALIN nvarchar (max),

             @FROM nvarchar(256),

             @TO nvarchar(256)

)

RETURNS nvarchar(max)

AS

BEGIN

 

   IF @VALIN IS NULL

      RETURN NULL

   IF @FROM IS NULL OR @TO IS NULL

      RETURN NULL

   IF LEN(@VALIN) = 0

      RETURN @VALIN

-- initialisation

   DECLARE @I INTEGER

   DECLARE @OUT nvarchar(max)

   SET @OUT = ''

-- lecture caractère par caractère

   SET @I =1

   WHILE @I <= LEN(@VALIN)

   BEGIN

      IF PATINDEX('%' + SUBSTRING(@VALIN, @I, 1)+ '%', @FROM) > 0

      BEGIN

         IF LEN(@TO) >= PATINDEX('%' + SUBSTRING(@VALIN, @I, 1)+ '%', @FROM)

            SET @OUT = @OUT + SUBSTRING(@TO, PATINDEX('%' + SUBSTRING(@VALIN, @I, 1)+ '%', @FROM), 1)

      END

      ELSE

         SET @OUT = @OUT + SUBSTRING(@VALIN, @I, 1)

      SET @I = @I + 1

   END

   RETURN @OUT

END

GO

We will now modify the Stored Procedure BuildTabLevelAndPath to use our new scalar function RRStringCharacter and pass them our parameters

Generate a CREATE script and save it to revert if needed.

Drop the store procedure, and rebuild it with this script :
this is an evolution off the Stored procedure create in previous article.

/****** Object:  StoredProcedure [dbo].[BuildTabLevelAndPath]    ******/

SET ANSI_NULLS ON

GO

 

SET QUOTED_IDENTIFIER ON

GO

 

CREATE PROCEDURE [dbo].[BuildTabLevelAndPath](@TabId INT, @IncludeChild BIT = 0)

       AS

       BEGIN

             DECLARE @ParentId INT, @Level INT, @TabPath NVARCHAR(255), @TabName NVARCHAR(50)

             SELECT @ParentId = ParentId, @TabName = TabName FROM dbo.[Tabs] WHERE TabID = @TabId

             IF @ParentId > 0

             BEGIN

                    SELECT

                           @Level = [Level] + 1,

                           @TabPath = TabPath + '//' + dbo.[RRStringCharacters](@TabName, '_ àáâãäåÀÁÂÃÄÅòóôõöøÒÓÔÕÖØèéêëÈÉÊËìíîïÌÍÎÏùúûüÙÚÛÜÿñÑçDz&?./''#:*', '_-aaaaaaAAAAAAooooooOOOOOOeeeeEEEEiiiiIIIIuuuuUUUUynNcC-')

                     FROM dbo.[Tabs] WHERE TabID = @ParentId

             END

             ELSE

             BEGIN

                    SELECT @Level = 0, @TabPath = '//' + dbo.[RRStringCharacters](@TabName, '_ àáâãäåÀÁÂÃÄÅòóôõöøÒÓÔÕÖØèéêëÈÉÊËìíîïÌÍÎÏùúûüÙÚÛÜÿñÑçDz&?./''#:*', '_-aaaaaaAAAAAAooooooOOOOOOeeeeEEEEiiiiIIIIuuuuUUUUynNcC-')

             END

            

             UPDATE dbo.[Tabs] SET [Level] = @Level, TabPath = @TabPath WHERE TabID = @TabId

            

             IF @IncludeChild = 1

             BEGIN

                    DECLARE @ChildTabs TABLE(TabID INT)

                    DECLARE @ChildID INT

                    INSERT INTO @ChildTabs SELECT TabID FROM dbo.[Tabs] WHERE ParentId =  @TabId

                    WHILE EXISTS (SELECT TOP 1 TabID FROM @ChildTabs)

                           BEGIN

                                  SET @ChildID = (SELECT TOP 1 TabID FROM @ChildTabs)

                                  EXEC dbo.[BuildTabLevelAndPath] @ChildID, @IncludeChild

                                  DELETE FROM @ChildTabs WHERE TabID = @ChildID

                           END

             END

       END

GO

Before :

After modification , clear cache, re save tab.


Hope this help.