While browsing through the SharePoint content database, I found a very useful TSQL utility function which can be used in any application. This function encodes the given html so that it can be safely used in XML tags and other html rendering requirements.
Please note, this function is originally provided in Sharepoint content database and I have just copied it because of its usefulness. PLEASE DO NOT CALL it directly from Sharepoint database as it is not recommended and supported by Microsoft. Just create this function in your own database and modify it as per your requirement.
SET ANSI_NULLS ONSET QUOTED_IDENTIFIER ONgoCREATE FUNCTION [dbo].[fn_HtmlEncode] (@Value NVARCHAR(1023),@PreserveNewLine BIT )RETURNS NVARCHAR(4000)ASBEGINDECLARE @Result NVARCHAR(4000)SELECT @Result = @ValueIF @Result IS NOT NULL AND LEN(@Result) > 0BEGINSELECT @Result = REPLACE(@Result, N'&', N'&')SELECT @Result = REPLACE(@Result, N'<', N'<')SELECT @Result = REPLACE(@Result, N'>', N'>')SELECT @Result = REPLACE(@Result, N'''', N''')SELECT @Result = REPLACE(@Result, N'"', N'"')IF @PreserveNewLine = 1SELECT @Result = REPLACE(@Result, CHAR(10), CHAR(10) + N'<br>')ENDRETURN @ResultEND
Post a Comment
Post a Comment