Link to home
Create AccountLog in
Avatar of n_srikanth4
n_srikanth4Flag for India

asked on

Escape Multiple Special Characters through query string URL

Question: How to  escape  multiple special characters ( -  ,  '  ,  &  ,  **  ,  ( , ) ,   / ,  \ ,  * , % , @ , # ) including leading and trailing spaces using Java Script .

I want to handle this using a Java Script mentioned here under(for a drill through report using the "Go to URL" option, "Action" Property  provided by SSRS 2008). Could you please correct my code below for atleast one of the Parameters posted below.

*********Note:  Please let me know how to use the CustomeCode if any  in the report expression , it is very Important, this is required

Java Script(used in the Report) :

+"&Audit_Manager="+Join(Parameters!Audit_Manager.Value, "&Audit_Manager=")
+"&Month_And_Year="+ FORMAT(Fields!ACTISSUEDATE.Value,"MMM-yy")+"','ChildW','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes'))"


Avatar of hpierson

JavaScript encodeURI() Function

I'm a little confused about your statement, it looks like you might need to escape some of your single and double quotes.

i.e. when you have a double quote nested within a double quote, you need to write


instead of just


for the inside double quote. Likewise for nested single quotes.
Avatar of Michel Plungjan
I am also confused. What does join do?

I would expect

to generate

Here is my suggestion
="javascript:var url='"+Format(Parameters!Start_Date.Value,"dd/MM/yyyy")
+"&Month_And_Year="+ FORMAT(Fields!ACTISSUEDATE.Value,"MMM-yy")

Open in new window

Avatar of n_srikanth4


Hi mplungjan:

"Join"  is very much required as the Parameters are Multi Value Parameters  and should be used in the report expression. The expression I have posted is working , but i need write the escape sequence for the special characters. So can you rewrite the code above(with Escape) by putting "Join" and   send across it to me.

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi mplungian:

    I have added the web refernce , added the Custom Function and used the function in the Report Expression using the keyword "Code" as you have mentioned above.
    I am almost there . It's working for most of the special Characters excluding  the  Apstrophe ( ' )  and Ampersand (& )

Could you please provide me  the custom code so that it works for  even  Apstrophe ( ' )  and Ampersand (& ) .

I will really appreciate your reply .

Kind Regards,

Try changing System.Web.HttpUtility.UrlEncode to System.Uri.EscapeDataString
as reported here: Html and Uri String Encoding without System.Web
Hi mplungian:

 Thanks for the Immdiate reply.

    I have changed the code as per your guidelines and  added the below custom code .
    Do I have to remove the System.Web Refernce l ??.
    Secondly  the above link is in C# and the Custom code in SSRS can only be written in VB.  
   So,  Please correct the code below if it is wrong .

Public Function URLEncode (ByVal inURL As String) As String
Dim outURL As String
outURL = System.Uri.EscapeDataString(inURL).ToString
Return outURL
End Function


I have no experience with either SSRS or C#
however since the SSRS worked with System.Web.HttpUtility.UrlEncode and that is accessible from C# I expected that System.Uri.EscapeDataString ALSO was accessible to SSRS

More information here